#include <bits/stdc++.h>
using namespace std;
bool check(int a, int b) {
  int x = 0, mul = 1;
  while (a) {
    if (a % 10 == 4 || a % 10 == 7) {
      x += mul * (a % 10);
      mul *= 10;
    }
    a /= 10;
  }
  return (x == b);
}
int main() {
  int a, b;
  cin >> a >> b;
  if (b > a)
    cout << b;
  else {
    a++;
    while (!check(a, b)) a++;
    cout << a;
  }
  return 0;
}
