#include <bits/stdc++.h>
using namespace std;
int main() {
  string s = "";
  long long n;
  cin >> n;
  while (1) {
    s += "47";
    sort(s.begin(), s.end());
    do {
      if (stoll(s) >= n) {
        cout << stoll(s) << '\n';
        return 0;
      }
    } while (next_permutation(s.begin(), s.end()));
  }
}
