#include <bits/stdc++.h>
using namespace std;
int ma[28], mam[28];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int i, m, n, x, j = 0, c = 0, r = 0, l, k, w = 0, s = 0, d = 0,
                            f = 0, sum = 0, mul, s1 = 0, s2 = 0, mx1 = -1,
                            mx = 1000000000000000000;
  cin >> n;
  string a;
  cin >> a;
  string b;
  for (i = n + 1; i <= 1000000; i++) {
    d = i;
    while (d != 0) {
      k = d % 10;
      if (k == 4) {
        b += '4';
      } else if (k == 7) {
        b += '7';
      }
      d /= 10;
    }
    reverse(b.begin(), b.end());
    if (a == b) {
      cout << i << endl;
      break;
    }
    b.clear();
  }
  return 0;
}
