#include <bits/stdc++.h>
using namespace std;
void HoH() {
  ios::sync_with_stdio(0);
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
}
int main() {
  HoH();
  long long k, a, b, h;
  string c = "", bb = "";
  cin >> a >> b;
  h = b;
  while (h > 0) {
    bb += (h % 10) + '0';
    h /= 10;
  }
  reverse(bb.begin(), bb.end());
  for (int i = a + 1; i <= 1000000000; i++) {
    c = "";
    h = i;
    k = i;
    while (h > 0) {
      if (h % 10 == 4 || h % 10 == 7) c += (h % 10) + '0';
      h /= 10;
    }
    reverse(c.begin(), c.end());
    if (c == bb) {
      cout << k;
      break;
    }
  }
  return 0;
}
