#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int MOD2 = 998244353;
const long long int MAX = 9187201950435737471;
const int N = 100005;
const int M = 100005;
const int INF = 2;
const double EPS = 1e-9;
const long double PI = acos(-1);
struct stableSum {
  int cnt = 0;
  vector<double> v, pref{0};
  void operator+=(double a) {
    assert(a >= 0);
    int s = ++cnt;
    while (s % 2 == 0) {
      a += v.back();
      v.pop_back(), pref.pop_back();
      s /= 2;
    }
    v.push_back(a);
    pref.push_back(pref.back() + a);
  }
  double val() { return pref.back(); }
};
int cmp(int a, int b) { return a > b; }
long long int po(long long int x, long long int y) {
  long long int ret = 1;
  while (y > 0) {
    if (y & 1) {
      ret = (ret * x);
    }
    y = y >> 1ll;
    x = (x * x);
  }
  return ret;
}
int d_sum(int n) {
  int ret = 0;
  while (n > 0) {
    ret += n % 10;
    n /= 10;
  }
  return ret;
}
void solve(int T) {
  string s;
  cin >> s;
  sort(s.begin(), s.end());
  reverse(s.begin(), s.end());
  int n = s.size();
  vector<int> v(5), d(4);
  for (int i = 0; i < 4; i++) d[i] = i + 1;
  set<int> t;
  int x = 0, l = 0;
  string f = "132645";
  while (f.size() < n) f += f;
  for (int i = n - 1; i >= 0; i--) {
    if ((s[i] == '1' && (!t.count(1))) || (s[i] == '6' && (!t.count(6))) ||
        (s[i] == '8' && (!t.count(8))) || (s[i] == '9' && (!t.count(9)))) {
      t.insert(s[i] - '0');
    } else {
      l += ((f[x] - '0') * (s[i] - '0'));
      l %= 7;
      x++;
    }
  }
  string k = "1689";
  do {
    long long int m = 0;
    for (int i = 3; i >= 0; i--) {
      m += (k[i] - '0') * (f[n - d[i]] - '0');
      m %= 7;
      v[d[i]] = k[i] - '0';
    }
    if ((m + l) % 7 == 0) {
      for (int i = 1; i <= 4; i++) cout << v[i];
      for (int i = 0; i < n; i++) {
        if ((s[i] == '1' && (t.count(1))) || (s[i] == '6' && (t.count(6))) ||
            (s[i] == '8' && (t.count(8))) || (s[i] == '9' && (t.count(9)))) {
          t.erase(s[i] - '0');
        } else {
          cout << s[i];
        }
      }
      return;
    }
  } while (next_permutation(d.begin(), d.end()));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  for (int i = 1; i <= T; i++) {
    solve(i);
  }
  return 0;
}
