#include <bits/stdc++.h>
using namespace std;
long long next(long long n) {
  if (n % 10 < 4)
    return n / 10 * 10 + 4;
  else if (n % 10 < 7)
    return n / 10 * 10 + 7;
  else
    return next(n / 10) * 10 + 4;
}
bool good(long long n, int a, int b) {
  if (n == 0) return (a == b);
  if (n % 10 == 4)
    a++;
  else if (n % 10 == 7)
    b++;
  else
    return false;
  return good(n / 10, a, b);
}
int main() {
  long long n;
  cin >> n;
  while (!good(n, 0, 0)) n = next(n);
  cout << n;
  return 0;
}
