#include <bits/stdc++.h>
using namespace std;
vector<long long> all;
void backtrack(long long x, int cnt4, int cnt7) {
  if (x > 1e10) return;
  if (cnt4 == cnt7) all.push_back(x);
  long long nxt = x * 10 + 4;
  backtrack(nxt, cnt4 + 1, cnt7);
  nxt = x * 10 + 7;
  backtrack(nxt, cnt4, cnt7 + 1);
}
int main() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  backtrack(0, 0, 0);
  sort(all.begin(), all.end());
  cout << *lower_bound(all.begin(), all.end(), n);
  return 0;
}
