#include <bits/stdc++.h>
using namespace std;
string s[1000];
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string n;
  cin >> n;
  long long int l = n.size(), i, c = 0;
  if (l & 1) {
    ++l;
    for (i = 1; i <= l / 2; ++i) cout << "4";
    for (i = 1; i <= l / 2; ++i) cout << "7";
    cout << "\n";
  } else {
    string m;
    for (i = 1; i <= l / 2; ++i) m += '4';
    for (i = 1; i <= l / 2; ++i) m += '7';
    do {
      s[++c] = m;
    } while (next_permutation(m.begin(), m.end()));
    long long int mn = pow(2, 63), x = stoll(n), y, lucky, flag = 0;
    for (i = 1; i <= c; ++i) {
      y = stoll(s[i]);
      if (y >= x and (y - x) < mn) {
        mn = min(mn, y - x);
        lucky = y;
        flag = 1;
      }
    }
    if (flag)
      cout << lucky << "\n";
    else {
      l += 2;
      for (i = 1; i <= l / 2; ++i) cout << "4";
      for (i = 1; i <= l / 2; ++i) cout << "7";
      cout << "\n";
    }
  }
  return 0;
}
