#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, i = 0, n = 1, l, j, c, k = 0, r = 0;
  scanf("%i %i", &a, &b);
  if (b > a)
    printf("%i", b);
  else {
    c = a + 1;
    while (1) {
      k = 0;
      n = 1;
      l = c;
      while (l != 0) {
        n *= 10;
        l /= 10;
      }
      n /= 10;
      l = c;
      while (l != 0) {
        r = 0;
        j = l / n;
        if (j == 4 || j == 7) {
          k *= 10;
          k += j;
        }
        l %= n;
        n /= 10;
      }
      if (k == b) {
        printf("%i", c);
        break;
      }
      c++;
    }
  }
  return 0;
}
