#include <bits/stdc++.h>
int a, b;
int ar[20];
int legal(int va, int vb) {
  int tem = 0, t, k = 1;
  while (va) {
    t = va % 10;
    if (t == 4 || t == 7) {
      tem += t * k;
      k *= 10;
    }
    va /= 10;
  }
  return tem == vb ? 1 : 0;
}
void deal() {
  int i;
  for (i = a + 1; !legal(i, b); i++)
    ;
  printf("%d\n", i);
}
int main(void) {
  while (2 == scanf("%d%d", &a, &b)) {
    deal();
  }
  return 0;
}
