import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Dmitry Abdrashitov
 */
public class beauty_da implements Runnable {
	
	private PrintWriter out;
	private BufferedReader in;
	private StringTokenizer st;
	
	private void solve() throws Exception {
		int n = nextInt();
		if (n < 1 || n > 100000) {
			throw new Exception("Wrong input data.");
		}
		int cnt = 0;
		int cur = 0;
		while (cnt < n) {
			cur++;
			int sum = 0;
			int dig = 0;
			int tmp = cur;
			while (tmp > 0) {
				dig++;
				sum += tmp % 10;
				tmp /= 10;
			}
			if (sum % dig == 0) {
				cnt++;
			}
		}
		out.println(cur);
	}
	
	public void run() {
		try {
			solve();
		} catch (Exception e) {
			apstenu(e);
		} finally {
			out.close();
		}
	}
	
	private void apstenu(Exception e) {
		e.printStackTrace();
		System.exit(239);
	}
	
	private int nextInt() throws Exception {
		return Integer.parseInt(nextToken());
	}
	
	private String nextToken() throws Exception {
		while (!st.hasMoreTokens()) {
			String line = in.readLine();
			st = new StringTokenizer(line);
		}
		return st.nextToken();
	}
	
	private beauty_da(String name) {
		try {
			out = new PrintWriter(new FileWriter(name + ".out"));
			in = new BufferedReader(new FileReader(name + ".in"));
			st = new StringTokenizer("");
		} catch (Exception e) {
			apstenu(e);
		}
	}

	public static void main(String[] args) {
		new Thread(new beauty_da("beauty")).start();
	}
}
