#include <bits/stdc++.h>
using namespace std;
long a;
long b;
int main() {
  cin >> a;
  cin >> b;
  long i;
  for (i = a + 1; i < 999999; i++) {
    long arr[100000];
    long j = i;
    int k;
    k = 0;
    while (j > 0) {
      int temp = j % 10;
      if (temp == 7 || temp == 4) arr[k++] = temp;
      j = j / 10;
    }
    long s;
    s = 0;
    int flag = 2;
    int m = 0;
    long bcopy;
    bcopy = b;
    while (bcopy > 0) {
      if (bcopy % 10 == arr[m] && m < k)
        ;
      else {
        flag = 1;
        break;
      }
      m++;
      bcopy = bcopy / 10;
      if (m == k && flag == 2 && bcopy == 0) flag = 0;
    }
    if (flag == 0 && k != 0) {
      cout << i;
      break;
    }
  }
  return 0;
}
