#include <bits/stdc++.h>
char s[10];
char c[10];
int check(int d) {
  int i = 0, j = 0, n;
  n = strlen(s);
  while (i < n && j < d) {
    if (s[i] == c[j]) {
      j++;
    } else if (s[i] == '4' || s[i] == '7') {
      return 0;
    }
    i++;
  }
  if (j < d) {
    return 0;
  }
  while (i < n) {
    if (s[i] == '4' || s[i] == '7') {
      return 0;
    }
    i++;
  }
  return 1;
}
void func(int a, int b) {
  int i = a + 1, d;
  sprintf(c, "%d", b);
  d = strlen(c);
  while (1) {
    sprintf(s, "%d", i);
    if (check(d)) {
      printf("%d\n", i);
      return;
    }
    i++;
  }
}
int main(int argc, char **argv) {
  int a, b;
  while (scanf("%d%d", &a, &b) == 2) {
    func(a, b);
  }
  return 0;
}
