#include <bits/stdc++.h>
using namespace std;
long long n;
vector<long long> res;
void lucky(long long num) {
  if (num > 1e10) {
    return;
  }
  int count4 = 0, count7 = 0;
  bool isSuper;
  string s = to_string(num);
  for (unsigned int i = 0; i < s.size(); i++) {
    if (s[i] == '4')
      count4++;
    else
      count7++;
  }
  (count4 == count7) ? isSuper = true : isSuper = false;
  if (num > 0 && isSuper) res.push_back(num);
  lucky(num * 10 + 4);
  lucky(num * 10 + 7);
}
int main() {
  ios_base::sync_with_stdio();
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  lucky(0);
  sort(res.begin(), res.end());
  vector<long long>::iterator it = lower_bound(res.begin(), res.end(), n);
  long long ans = it - res.begin();
  cout << res[ans] << endl;
  return 0;
}
