#include <bits/stdc++.h>
using namespace std;
int countd(long long m) {
  long long c = 0;
  while (m != 0) {
    long long k = m % 10;
    c++;
    m /= 10;
  }
  return c;
}
int distinct(long long m) {
  long long arr[10] = {0};
  while (m != 0) {
    long long c = m % 10;
    arr[c] = 1;
    m = m / 10;
  }
  long long count = 0;
  for (long long j = 0; j < 10; j++) {
    if (arr[j]) {
      count++;
    }
  }
  return count;
}
long long nextd(long long n) {
  while (n < INT_MAX) {
    int d = distinct(n + 1);
    int d1 = countd(n + 1);
    if (d == d1) {
      return n + 1;
    } else {
      n++;
    }
  }
  return -1;
}
int main() {
  long long n;
  cin >> n;
  cout << nextd(n);
  return 0;
}
