#include <bits/stdc++.h>
using namespace std;
const double pi = 3.14159265358979323846;
void rw() {}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  vector<long long> s;
  long long n, c, f, se;
  cin >> n;
  s.push_back(4);
  s.push_back(7);
  for (int i = 0; i < s.size(); i++) {
    f = 0, se = 0;
    c = s[i];
    while (c) {
      if (c % 10 == 4)
        f++;
      else
        se++;
      c /= 10;
    }
    if (s[i] >= n && f == se) {
      cout << s[i] << "\n";
      break;
    } else {
      s.push_back(s[i] * 10 + 4);
      s.push_back(s[i] * 10 + 7);
    }
  }
  return 0;
}
