#include <bits/stdc++.h>
using namespace std;
long long n;
long long mini = 1e12;
void solve(long long lucky = 0, int c = 0) {
  if (lucky > 1e11) return;
  if (lucky >= n && c == 0) mini = min(mini, lucky);
  solve(lucky * 10 + 4, c + 1);
  solve(lucky * 10 + 7, c - 1);
}
int main() {
  cin >> n;
  solve();
  cout << mini;
  return 0;
}
