#include <bits/stdc++.h>
const long long inf = 0x3f3f3f3f3f3f3f3LL;
const long long mod = (long long)1e9 + 7;
using namespace std;
template <class T>
void smin(T& a, T val) {
  if (a > val) a = val;
}
template <class T>
void smax(T& a, T val) {
  if (a < val) a = val;
}
const long long N = 7e6 + 10;
long long n;
string x;
bool check(long long num) {
  string tt = "";
  while (num) {
    long long d = num % 10;
    if (d == 4 or d == 7) tt += (char)(d + '0');
    num /= 10;
  }
  if ((long long)(tt.size()) != (long long)(x.size())) return 0;
  reverse(tt.begin(), tt.end());
  for (long long i = 0; i < (long long)(tt.size()); ++i)
    if (tt[i] != x[i]) return 0;
  return 1;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> x;
  for (long long i = n + 1; i <= N; ++i) {
    if (check(i)) {
      cout << i;
      exit(0);
    }
  }
  throw;
  return 0;
}
