#include <bits/stdc++.h>
using namespace std;
double EPS = 1e-9;
int INF = 2000000000;
long long INFF = 8000000000000000000LL;
double PI = acos(-1);
inline string IntToString(int a) {
  char x[100];
  sprintf(x, "%d", a);
  string s = x;
  return s;
}
inline int StringToInt(string a) {
  char x[100];
  int res;
  strcpy(x, a.c_str());
  sscanf(x, "%d", &res);
  return res;
}
inline string GetString(void) {
  char x[1000005];
  scanf("%s", x);
  string s = x;
  return s;
}
inline bool angka(char a) { return (a >= '0' && a <= '9'); }
inline bool kecil(char a) { return (a >= 'a' && a <= 'z'); }
inline bool besar(char a) { return (a >= 'A' && a <= 'Z'); }
inline string uppercase(string s) {
  int n = (int)s.size();
  for (int(i) = (0); (i) < (n); (i)++)
    if (kecil(s[i])) s[i] = s[i] - 'a' + 'A';
  return s;
}
inline string lowercase(string s) {
  int n = (int)s.size();
  for (int(i) = (0); (i) < (n); (i)++)
    if (besar(s[i])) s[i] = s[i] - 'A' + 'a';
  return s;
}
string mask(int a) {
  string res;
  while (a > 0) {
    char tmp = (a % 10) + '0';
    if (tmp == '7' || tmp == '4') res = tmp + res;
    a /= 10;
  }
  return res;
}
int n;
string s;
int main() {
  cin >> n >> s;
  while (1) {
    n++;
    if (mask(n) == s) {
      printf("%d\n", n);
      return 0;
    }
  }
  return 0;
}
