#include <bits/stdc++.h>
using namespace std;
vector<long long> lucky;
void nums(long long number, int fours, int sevens) {
  if (number > 1e10) return;
  if (fours == sevens) lucky.push_back(number);
  nums(number * 10 + 7, fours, sevens + 1);
  nums(number * 10 + 4, fours + 1, sevens);
}
int main() {
  nums(4, 1, 0);
  nums(7, 0, 1);
  long long n;
  cin >> n;
  sort(lucky.begin(), lucky.end());
  cout << lucky[lower_bound(lucky.begin(), lucky.end(), n) - lucky.begin()]
       << endl;
  return 0;
}
