import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class gold_nv1 {
	public static void main(String[] args) {
		new gold_nv1().run();
	}

	BufferedReader br;
	StringTokenizer in;
	PrintWriter out;

	static final Random rand = new Random(556668949239L);

	static ArrayList<String> ans = new ArrayList<String>();

	public String nextToken() throws IOException {
		while (in == null || !in.hasMoreTokens()) {
			in = new StringTokenizer(br.readLine());
		}
		return in.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	boolean check(String s) {
		BigInteger a = new BigInteger(s);
		BigInteger b = a.multiply(a);
		String t = a.toString();
		String r = b.toString();
		return (r.indexOf(t) == r.length() - t.length());
	}

	public void solve() throws IOException {
		int k = nextInt();
		ans.add("0");
		ans.add("1");
		ans.add("5");
		ans.add("6");
		while (ans.size() < k) {
			int n = ans.size();
			String s1 = ans.get(n - 2);
			String s2 = ans.get(n - 1);
			boolean f1 = false;
			boolean f2 = false;
			rand.nextLong();
			while (!(f1 && f2)) {
				f1 = false;
				f2 = false;
				for (int i = 1; i < 10; i++) {
					if (!f1 && check(Integer.toString(i) + s1)) {
						f1 = true;
						if (!f2 && check(Integer.toString(i) + s2)) {
							f2 = true;
							if ((Integer.toString(i) + s1).compareTo(Integer
									.toString(i) + s2) < 0) {
								ans.add(Integer.toString(i) + s1);
								ans.add(Integer.toString(i) + s2);
							} else {
								ans.add(Integer.toString(i) + s2);
								ans.add(Integer.toString(i) + s1);
							}
						} else
							ans.add(Integer.toString(i) + s1);
					}
					if (!f2 && check(Integer.toString(i) + s2)) {
						f2 = true;
						ans.add(Integer.toString(i) + s2);
					}
				}
				if (!f1 && !f2) {
					s1 = "0" + s1;
					s2 = "0" + s2;
					continue;
				}
				if (!f1) {
					s1 = "0" + s1;
					s2 = ans.get(ans.size() - 1);
				}
				if (!f2) {
					s2 = "0" + s2;
					s1 = ans.get(ans.size() - 1);
				}
				if (ans.size() > k)
					break;
			}
		}
		//for (int i = 0; i < k; i++)
		out.println(ans.get(k - 1));
	}

	public void run() {
		try {
			br = new BufferedReader(new FileReader("gold.in"));
			out = new PrintWriter("gold.out");
			solve();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
}