#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const double pi = 3.141592653589793238462643383279;
void solve() {
  long long num;
  cin >> num;
  long long dig = log10(num) + 1, i = 0;
  string ans = "";
  while (i < dig / 2) ans += "47", i++;
  if (dig & 1) ans += "47";
  sort((ans).begin(), (ans).end());
  do {
    long long val = stoll(ans);
    if (val >= num) {
      cout << val;
      return;
    }
  } while (next_permutation(ans.begin(), ans.end()));
  ans += "47";
  sort((ans).begin(), (ans).end());
  do {
    long long val = stoll(ans);
    if (val >= num) {
      cout << val;
      return;
    }
  } while (next_permutation(ans.begin(), ans.end()));
}
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long testCases = 1;
  while (testCases--) {
    solve();
    cout << "\n";
  }
}
