#include <bits/stdc++.h>
using namespace std;
long long N;
bool found = false;
void dfs(int dig, long long cur, int c4, int c7) {
  if (found) return;
  if (dig == 0) {
    if (cur >= N && c4 == c7) {
      cout << cur << endl;
      found = true;
    }
  } else {
    dfs(dig - 1, cur * 10 + 4, c4 + 1, c7);
    dfs(dig - 1, cur * 10 + 7, c4, c7 + 1);
  }
  return;
}
int main() {
  cin >> N;
  for (int dig = 2; !found; dig += 2) dfs(dig, 0, 0, 0);
  return 0;
}
