#include <bits/stdc++.h>
using namespace std;
int luckyNum(long long a) {
  long long n = 0;
  for (long long j = a; j > 0; j /= 10)
    if ((j % 10) == 4 || (j % 10) == 7) n += 1;
  return n;
}
long long dec(long long b) {
  for (long long m = 1;; m *= 10) {
    if (((b / m) % 10) == 4 || ((b / m) % 10) == 7) {
      b = b + m - (b % m);
      break;
    }
  }
  return b;
}
long long inc(long long b) {
  for (long long m = 1, t = 0, f = 0;; m *= 10) {
    int d = (b / m) % 10;
    if (d == 9) {
      f += 1;
      continue;
    }
    if ((f <= 0 && d == 4) || (f <= 1 && d == 7)) {
      t = t * 10 + 4;
      continue;
    }
    if (f == 1 && d == 4) {
      b = b + 3 * m - (b % m) + t * 10 + 4;
      break;
    }
    if (d == 4 || d == 7) {
      b = b + m - (b % m) + t * 100 + 44;
      break;
    }
    if (f) {
      b = b + m - (b % m) + ((d == 3 || d == 6) ? t : t * 10 + 4);
      break;
    }
    if (d < 4) {
      b = b - (b % (10 * m)) + 4 * m + t;
      break;
    }
    if (d < 7) {
      b = b - (b % (10 * m)) + 7 * m + t;
      break;
    }
    f += 1;
  }
  return b;
}
long long next(long long a) {
  long long b = a + 1;
  if (luckyNum(b) > luckyNum(a)) return dec(b);
  if (luckyNum(b) < luckyNum(a)) return inc(b);
  return b;
}
int main() {
  long long a, l, b = 0, m = 1, d;
  cin >> a >> l;
  d = a + l - 1;
  for (; l >= 10; l /= 10, a /= 10, d /= 10, m *= 10) {
    b += (a % 10) * m;
  }
  for (long long i = next(a);;) {
    int cur = i;
    for (long long k = 0; a + k <= d; k++) {
      int n1 = luckyNum(a + k);
      int n2 = luckyNum(i + k);
      if (n1 < n2) {
        for (int j = 0; j < n2 - n1; j++) i = dec(i + k) - k;
        break;
      }
      if (n1 > n2) {
        for (int j = 0; j < n1 - n2; j++) i = inc(i + k) - k;
        break;
      }
    }
    if (i == cur) {
      b += i * m;
      break;
    }
  }
  cout << b << endl;
  return 0;
}

### Prompt

Please create a solution in CPP to the following problem:

Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

One day Petya came across an interval of numbers [a, a + l - 1]. Let F(x) be the number of lucky digits of number x. Find the minimum b (a < b) such, that F(a) = F(b), F(a + 1) = F(b + 1), ..., F(a + l - 1) = F(b + l - 1).

Input

The single line contains two integers a and l (1 ≤ a, l ≤ 109) — the interval's first number and the interval's length correspondingly.

Output

On the single line print number b — the answer to the problem.

Examples

Input

7 4


Output

17


Input

4 7


Output

14

Note

Consider that [a, b] denotes an interval of integers; this interval includes the boundaries. That is, <image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int luckyNum(long long a) {
  long long n = 0;
  for (long long j = a; j > 0; j /= 10)
    if ((j % 10) == 4 || (j % 10) == 7) n += 1;
  return n;
}
long long dec(long long b) {
  for (long long m = 1;; m *= 10) {
    if (((b / m) % 10) == 4 || ((b / m) % 10) == 7) {
      b = b + m - (b % m);
      break;
    }
  }
  return b;
}
long long inc(long long b) {
  for (long long m = 1, t = 0, f = 0;; m *= 10) {
    int d = (b / m) % 10;
    if (d == 9) {
      f += 1;
      continue;
    }
    if ((f <= 0 && d == 4) || (f <= 1 && d == 7)) {
      t = t * 10 + 4;
      continue;
    }
    if (f == 1 && d == 4) {
      b = b + 3 * m - (b % m) + t * 10 + 4;
      break;
    }
    if (d == 4 || d == 7) {
      b = b + m - (b % m) + t * 100 + 44;
      break;
    }
    if (f) {
      b = b + m - (b % m) + ((d == 3 || d == 6) ? t : t * 10 + 4);
      break;
    }
    if (d < 4) {
      b = b - (b % (10 * m)) + 4 * m + t;
      break;
    }
    if (d < 7) {
      b = b - (b % (10 * m)) + 7 * m + t;
      break;
    }
    f += 1;
  }
  return b;
}
long long next(long long a) {
  long long b = a + 1;
  if (luckyNum(b) > luckyNum(a)) return dec(b);
  if (luckyNum(b) < luckyNum(a)) return inc(b);
  return b;
}
int main() {
  long long a, l, b = 0, m = 1, d;
  cin >> a >> l;
  d = a + l - 1;
  for (; l >= 10; l /= 10, a /= 10, d /= 10, m *= 10) {
    b += (a % 10) * m;
  }
  for (long long i = next(a);;) {
    int cur = i;
    for (long long k = 0; a + k <= d; k++) {
      int n1 = luckyNum(a + k);
      int n2 = luckyNum(i + k);
      if (n1 < n2) {
        for (int j = 0; j < n2 - n1; j++) i = dec(i + k) - k;
        break;
      }
      if (n1 > n2) {
        for (int j = 0; j < n1 - n2; j++) i = inc(i + k) - k;
        break;
      }
    }
    if (i == cur) {
      b += i * m;
      break;
    }
  }
  cout << b << endl;
  return 0;
}

```