#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
using u64 = uint64_t;
using u128 = __uint128_t;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
void solve() {
  int a, b;
  cin >> a >> b;
  int x = a + 1;
  while (true) {
    string str = to_string(x);
    string temp;
    for (auto& ch : str)
      if (ch == '4' or ch == '7') temp += ch;
    if (temp.empty()) {
      x++;
      continue;
    }
    int k = stoi(temp);
    if (k == b) {
      cout << stoi(str) << '\n';
      break;
    }
    x++;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
  return 0;
}
