#include <bits/stdc++.h>
using namespace std;
const long long N = 1e10;
vector<long long> ans;
void dfs(long long x) {
  if (x > N) return;
  ans.push_back(x);
  dfs(x * 10 + 4);
  dfs(x * 10 + 7);
  return;
}
void solve() {
  ans.clear();
  dfs(0);
  long long n;
  cin >> n;
  vector<long long> v;
  for (auto it : ans) {
    long long first = it;
    long long a = 0, b = 0;
    while (first) {
      int rem = first % 10;
      if (rem == 7)
        a++;
      else
        b++;
      first = first / 10;
    }
    if (a == b) v.push_back(it);
  }
  sort(v.begin(), v.end());
  long long index = lower_bound(v.begin(), v.end(), n) - v.begin();
  cout << v[index] << endl;
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  solve();
  return 0;
}
