#include <bits/stdc++.h>
using namespace std;
const long long inf = INT_MAX;
const long double ep = 0.0000001;
const long double pi = acos(-1.0);
const long long md = 1e9 + 7;
long long n, m, k, i, j, t, flag = 0, c = 0;
bool comp(vector<long long> v, long long x) {
  long long s = 0;
  for (i = 0; i < v.size(); ++i) {
    s = s * 10 + v[i];
  }
  if (s >= x) return 1;
  return 0;
}
void solve() {
  cin >> n;
  long long d = log10(n) + 1;
  if (d % 2 == 0) {
    long long s = 0;
    for (i = 0; i < d / 2; ++i) s = s * 10 + 7;
    for (i = 0; i < d / 2; ++i) s = s * 10 + 4;
    if (n > s) d += 2;
  }
  if (d % 2 == 1) d += 1;
  vector<long long> v;
  for (i = 0; i < d / 2; ++i) v.push_back(4);
  for (i = 0; i < d / 2; ++i) v.push_back(7);
  while (!comp(v, n)) {
    next_permutation(v.begin(), v.end());
  }
  for (i = 0; i < d; ++i) cout << v[i];
}
signed main() {
  ios_base::sync_with_stdio(false);
  long long t = 1;
  while (t--) solve();
}
