#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff;
inline int reint() {
  int d;
  scanf("%d", &d);
  return d;
}
inline long relong() {
  long l;
  scanf("%ld", &l);
  return l;
}
inline char rechar() {
  scanf(" ");
  return getchar();
}
inline double redouble() {
  double d;
  scanf("%lf", &d);
  return d;
}
inline string restring() {
  string s;
  cin >> s;
  return s;
}
int mask(int a) {
  char str[10];
  sprintf(str, "%d", a);
  char ans[10];
  int j = 0;
  for (int i = (0); i < (strlen(str)); i++) {
    if (str[i] == '4' || str[i] == '7') {
      ans[j++] = str[i];
    }
  }
  int res = 0;
  for (int i = (0); i < (j); i++) {
    res += ans[i] - '0';
    if (i != j - 1) {
      res *= 10;
    }
  }
  return res;
}
int c, b;
int main(void) {
  cin >> c >> b;
  c++;
  while (mask(c) != b) {
    c++;
  }
  cout << c << endl;
  return 0;
}
