#include <bits/stdc++.h>
using namespace std;
char s[10086];
bool check(int a, int b) {
  int num[10], t = 0;
  while (a) {
    num[t++] = a % 10;
    a /= 10;
  }
  int s = 0;
  for (int i = t - 1; i >= 0; i--) {
    if (num[i] == 4 || num[i] == 7) {
      s *= 10;
      s += num[i];
    }
  }
  if (s == b) return true;
  return false;
}
int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  if (a < b)
    cout << b << endl;
  else {
    while (1) {
      a++;
      if (check(a, b)) {
        cout << a << endl;
        return 0;
      }
    }
  }
}
