#include <bits/stdc++.h>
using namespace std;
int i, j, k, a, b, rev, len;
int main() {
  scanf("%d%d", &a, &b);
  for (i = max(a + 1, b);; i++) {
    for (j = i, k = rev = len = 0; j; j /= 10)
      if (j % 10 == 4 || j % 10 == 7) rev *= 10, rev += (j % 10), len++;
    for (; rev; rev /= 10) k *= 10, k += (rev % 10);
    if (k == b) {
      printf("%d\n", i);
      return 0;
    }
  }
  return 0;
}
