#include <bits/stdc++.h>
using namespace std;
long long x, y;
long long A[30], B[30];
int f[30], cnt[100005];
int Calc(int x) { return cnt[x / 100000] + cnt[x % 100000]; }
long long Next(long long x) {
  long long xx = x % 10;
  if (xx <= 2) return x + 1;
  if (xx == 3) return x + 2;
  if (xx == 4) return x + 3;
  if (xx == 5) return x + 1;
  if (xx == 6) return x + 2;
  if (xx == 8) return x + 1;
  if (xx == 7) {
    long long a = x / 10, b = 1;
    while (a % 10 == 7) {
      ++b;
      a /= 10;
    }
    xx = a % 10;
    if (xx <= 2 || xx == 5 || xx == 8) return x + A[b] * 6 + 1;
    if (xx == 3 || xx == 6)
      return (b == 1) ? (x + 3) : (x + A[b] * 6 + 1 - B[b - 1] * 4);
    if (xx == 4) return x + B[b] * 2 + A[b] * 6 + 1;
    if (xx == 9) {
      int c = 0;
      while (a % 10 == 9) {
        ++c;
        a /= 10;
      }
      x = x - A[b + c] * 9 + A[b] * 2 + B[b + c];
      xx = a % 10;
      if (xx == 4 || xx == 7)
        ++b;
      else if (xx == 3 || xx == 6)
        --b;
      return x + A[b] * 4;
    }
  }
  if (xx == 9) {
    long long a = x / 10, b = 10;
    while (a % 10 == 9) {
      b *= 10;
      a /= 10;
    }
    xx = a % 10;
    if (xx == 4 || xx == 7)
      return x + 5;
    else if (xx == 3 || xx == 6)
      return x + b + 1;
    else
      return x + 1;
  }
}
long long Solve(long long x, long long y) {
  if (y == 1) return Next(x);
  long long ans = Solve(x / 10, (x + y - 1) / 10 - x / 10 + 1) * 10 + x % 10;
  if (y > 20)
    return ans;
  else {
    for (int i = 1; i <= y; ++i) f[i] = Calc(x + i - 1);
    for (long long tmp = Next(x); tmp < ans; tmp = Next(tmp)) {
      bool flag = 1;
      for (int i = 1; i <= y; ++i)
        if (Calc(tmp + i - 1) != f[i]) {
          flag = 0;
          break;
        }
      if (flag) return tmp;
    }
    return ans;
  }
}
int main() {
  A[1] = 1;
  B[1] = 10;
  for (int i = 1; i < 100000; ++i)
    cnt[i] = cnt[i / 10] + (i % 10 == 4 || i % 10 == 7);
  for (int i = 2; i <= 15; ++i) A[i] = A[i - 1] * 10 + 1, B[i] = B[i - 1] * 10;
  scanf("%I64d%I64d", &x, &y);
  printf("%I64d\n", Solve(x, y));
  return 0;
}
