#include <bits/stdc++.h>
using namespace std;
set<long long> s;
void solve(long long i) {
  s.insert(i);
  if (i >= 1e9) {
    return;
  }
  solve(i * 10 + 4);
  solve(i * 10 + 7);
}
bool can(long long t) {
  int c = 0, c1 = 0;
  while (t) {
    if (t % 10 == 4)
      c++;
    else
      c1++;
    t /= 10;
  }
  if (c == c1)
    return true;
  else
    return false;
}
int main() {
  long long x;
  cin >> x;
  solve(0);
  set<long long>::iterator y;
  y = s.lower_bound(x);
  long long z;
  while (1) {
    if (can(*y)) {
      cout << *y;
      return 0;
    }
    y = s.upper_bound(*y);
  }
}
