#include <bits/stdc++.h>
using namespace std;
string mask(int a) {
  stringstream ss;
  ss << a;
  string s = ss.str();
  string ans = "";
  for (int i = 0; i < s.length(); i++)
    if (s[i] == '7' || s[i] == '4') ans += s[i];
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int a;
  string b;
  cin >> a >> b;
  for (int i = a + 1; i < 1e7; i++) {
    if (mask(i) == b) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}
