#include <bits/stdc++.h>
int lucky(int x) {
  int ret = 0;
  int mul = 1;
  while (x) {
    int tmp = x % 10;
    if (tmp == 4 || tmp == 7) {
      ret += tmp * mul;
      mul *= 10;
    }
    x /= 10;
  }
  return ret;
}
int main() {
  int a, b;
  std::cin >> a >> b;
  for (int i = a + 1; i <= 1000000; ++i) {
    if (lucky(i) == b) {
      std::cout << i;
      break;
    }
  }
}
