#include <bits/stdc++.h>
using namespace std;
int mask(char *str) {
  int i, n = 0;
  char temp[10];
  for (i = 0; i < 11; i++) temp[i] = ' ';
  for (i = 0; i < 10; i++) {
    if (str[i] == '4' || str[i] == '7') {
      temp[n++] = str[i];
    }
  }
  return atoi(temp);
}
int main() {
  long int result = 0, aa, bb, q, i = 0, j = 0, z, step;
  char a[10], b[10], t[10];
  int flag = 0;
  cin >> a >> b;
  aa = atoi(a);
  bb = atoi(b);
  if (aa < bb) {
    result = bb;
  } else {
    if (mask(a) == 0 || aa == bb) {
      step = 1;
      for (j = 0; j < max(strlen(b), strlen(a) - 1); j++) step *= 10;
      result = bb + step;
      if (result <= aa) flag = 1;
    } else {
      for (i = aa + 1; i < aa + 999999; i++) {
        sprintf(t, "%d", i);
        if (mask(t) == bb) {
          result = i;
          break;
        }
      }
    }
  }
  if (flag == 1) {
    for (i = aa + 1; i < aa + 999999; i++) {
      sprintf(t, "%d", i);
      if (mask(t) == bb) {
        result = i;
        break;
      }
    }
  }
  cout << result;
  return 0;
}
