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