#include <bits/stdc++.h>
using namespace std;
const long long M = 1e12;
set<long long> s;
void generate_lucky(long long nr, int balance) {
  if (nr > M) return;
  if (balance == 0) s.insert(nr);
  generate_lucky(10 * nr + 4, balance + 1);
  generate_lucky(10 * nr + 7, balance - 1);
}
int main() {
  std::ios::sync_with_stdio(false);
  generate_lucky(4, 1);
  generate_lucky(7, -1);
  int n;
  cin >> n;
  long long res = *(s.lower_bound(n));
  cout << res << "\n";
  return 0;
}
