#include <bits/stdc++.h>
using namespace std;
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
}
void solve() {
  vector<string> ve;
  string S = "44447777", T = "444777", X = "4477", G = "47", Y = "4444477777";
  do {
    ve.push_back(G);
  } while (next_permutation(G.begin(), G.end()));
  do {
    ve.push_back(X);
  } while (next_permutation(X.begin(), X.end()));
  do {
    ve.push_back(T);
  } while (next_permutation(T.begin(), T.end()));
  do {
    ve.push_back(S);
  } while (next_permutation(S.begin(), S.end()));
  do {
    ve.push_back(Y);
  } while (next_permutation(Y.begin(), Y.end()));
  vector<long long> ans;
  for (int i = 0; i < ve.size(); i++) {
    long long res = 0;
    for (int j = 0; j < ve[i].size(); j++) {
      res *= 10;
      res += (ve[i][j] - '0');
    }
    ans.push_back(res);
  }
  long long N;
  cin >> N;
  sort(ans.begin(), ans.end());
  for (int i = 0; i < ans.size(); i++) {
    if (N <= ans[i]) {
      cout << ans[i];
      return;
    }
  }
}
int main() {
  fast();
  int T = 1;
  while (T--) {
    solve();
  }
}
