#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  vector<long long int> A[5];
  for (long long int i = 0; i < 5; i++) {
    for (long long int j = 0; j <= i; j++) A[i].push_back(4);
    for (long long int j = 0; j <= i; j++) A[i].push_back(7);
  }
  set<long long int> st;
  for (long long int j = 0; j < 5; j++) {
    do {
      long long int x = 0;
      for (auto i : A[j]) x = x * 10 + i;
      st.insert(x);
    } while (next_permutation(A[j].begin(), A[j].end()));
  }
  long long int n;
  cin >> n;
  for (auto i : st) {
    if (i >= n) {
      cout << i;
      return 0;
    }
  }
}
