#include <bits/stdc++.h>
int mask(int num) {
  int res = 0, a;
  while (num != 0) {
    a = num % 10;
    num /= 10;
    if (a == 4 || a == 7) {
      res = res * 10 + a;
    }
  }
  return res;
}
int main() {
  int a, b;
  scanf("%d%d", &a, &b), ++a, b = mask(b);
  while (mask(a) != b) {
    ++a;
  }
  printf("%d\n", a);
  return 0;
}
