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