#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  int n;
  string y;
  std::cin >> n;
  while (true) {
    y += "47";
    sort(y.begin(), y.end());
    do {
      if (stoll(y) >= n) {
        std::cout << y << '\n';
        return 0;
      }
    } while (next_permutation(y.begin(), y.end()));
  }
  return 0;
}
