#include <bits/stdc++.h>
using namespace std;
long long s = 0, nb = 0, t[10];
string ch, res = "";
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ch = "1689";
  do {
    nb = 0;
    for (long long i = 0; i < 4; i++) {
      nb = nb * 10 + ch[i] - '0';
    }
    t[nb % 7] = nb;
  } while (next_permutation(ch.begin(), ch.end()));
  cin >> ch;
  set<long long> st;
  st.insert(1);
  st.insert(6);
  st.insert(8);
  st.insert(9);
  nb = 0;
  for (long long i = 0; ch[i]; i++) {
    if (st.count(ch[i] - '0')) {
      st.erase(ch[i] - '0');
      continue;
    }
    if (ch[i] == '0') {
      s++;
      continue;
    }
    nb = nb * 10 + ch[i] - '0';
    nb = nb % 7;
    res += ch[i];
  }
  nb = nb * 10000;
  cout << res;
  for (long long i = 0; i < 7; i++) {
    if ((nb + t[i]) % 7 == 0) {
      cout << t[i];
      break;
    }
  }
  for (long long i = 0; i < s; i++) cout << 0;
  return 0;
}
