uses
  SysUtils;

var i, k, n, j, l: longint;
    s: string;
    f: boolean;

begin
  reset(input, 'number.in');
  rewrite(output, 'number.out');
  k := 0;
  read(n);
  i := 1;
  while (k < n) do
    begin
      s := inttostr(i);
      f := true;
      l := length(s);
      for j := 1 to l do
        if s[j] <> s[l - j + 1] then
          begin
            f := false;
            break;
         end;
      if f then inc(k);
      inc(i);
    end;
  writeln(s);
end.