#include <bits/stdc++.h>
using namespace std;
bool ok(int x, int y) {
  while (x) {
    int t = x % 10;
    if ((t == 4 || t == 7) && (t != y % 10)) return false;
    if (t == y % 10) y /= 10;
    x /= 10;
  }
  if (y == 0)
    return true;
  else
    return false;
}
int main(int argc, char *argv[]) {
  int a, b;
  while (scanf("%d%d", &a, &b) != EOF) {
    if (b > a)
      printf("%d\n", b);
    else {
      int c = a + 1;
      while (!ok(c, b)) c++;
      printf("%d\n", c);
    }
  }
  return 0;
}
