#include <bits/stdc++.h>
using namespace std;
const int N = 100500;
string s, s2, s3, s4, n, ans[100], s5;
bool ok[12];
long long kol;
long long ok1(string s, long long b) {
  long long carry = 0;
  vector<int> c;
  for (int i = s.length() - 1; i >= 0; i--) {
    c.push_back(s[i] - '0');
  }
  for (int i = c.size() - 1; i >= 0; i--) {
    long long cur = c[i] + carry * 10;
    c[i] = cur / b;
    carry = cur % b;
  }
  return carry;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> s;
  n = "1689";
  do {
    ans[++kol] = n;
  } while (next_permutation(n.begin(), n.end()));
  for (int i = 0; i < s.size(); i++) {
    if ((s[i] == '1' || s[i] == '6' || s[i] == '8' || s[i] == '9') &&
        !ok[s[i] - '0']) {
      ok[s[i] - '0'] = 1;
      continue;
    }
    s2 += s[i];
  }
  sort(s2.begin(), s2.end());
  reverse(s2.begin(), s2.end());
  for (int i = 0; i < s2.size(); i++) {
    if (s2[i] == '0' || i == s2.size() - 1) {
      s4 = s2.substr(0, i);
      s5 = s2.substr(i, s.size() - i);
      for (int j = 1; j <= kol; j++) {
        if (ok1(s4 + ans[j] + s5, 7) == 0) {
          cout << s4 << ans[j] << s5;
          return 0;
        }
      }
    }
  }
  cout << "1869";
  return 0;
}
