#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
int main() {
  string s;
  cin >> s;
  map<int, int> cnt;
  for (int i = 0; i < s.size(); ++i) {
    cnt[s[i] - '0']++;
  }
  cnt[1]--;
  cnt[6]--;
  cnt[8]--;
  cnt[9]--;
  string ans = "";
  for (int i = 1; i <= 9; ++i) {
    for (int j = 0; j < cnt[i]; ++j) ans += (char)('0' + i);
  }
  int powr = 1;
  int su = 0;
  for (int i = 0; i < ans.size(); ++i) {
    su = su * 10 + (ans[i] - '0');
    su %= 7;
  }
  vector<int> perm = {1, 6, 8, 9};
  do {
    int n =
        su * 10000 + perm[0] * 1000 + perm[1] * 100 + perm[2] * 10 + perm[3];
    if (n % 7 == 0) {
      cout << ans;
      for (int x : perm) cout << x;
      for (int i = 0; i < cnt[0]; ++i) cout << 0;
      return 0;
    }
  } while (next_permutation(perm.begin(), perm.end()));
  return 0;
}
