#include <bits/stdc++.h>
using namespace std;
const long long int INF = LLONG_MAX;
vector<long long int> v1, v2;
string s1, s2, s3;
long long int ara[13];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int a, b, c, d, e, f, i, j, k, cnt1 = 0, cnt2 = 0, sum1 = 0,
                                           sum2 = 0, chk1 = 0, chk2 = 0, T;
  cin >> a >> b;
  stringstream ss;
  ss << b;
  ss >> s2;
  long long int sz = s2.size();
  for (i = a + 1;; i++) {
    long long int chk = 0;
    ss.clear();
    ss << i;
    ss >> s1;
    long long int x = 0;
    for (j = 0; j < s1.size(); j++) {
      if (x < sz && s1[j] == s2[x]) {
        x++;
      } else if (s1[j] == '7' || s1[j] == '4') {
        chk = 1;
        break;
      }
    }
    if (x == sz && chk == 0) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}
