#include <bits/stdc++.h>
using namespace std;
int a[5] = {0, 1, 6, 8, 9};
int b[5];
int p;
bool Free[5], ok = 0;
int n;
void solve() {
  int tmp = p;
  for (int i = 1; i <= 4; i++) tmp = (tmp * 3 + a[b[i]]) % 7;
  if (tmp == 0) {
    for (int i = 1; i <= 4; i++) cout << a[b[i]];
    ok = 1;
    return;
  }
}
void gen(int i) {
  if (ok) return;
  for (int j = 1; j <= 4; j++)
    if (Free[j]) {
      b[i] = j;
      Free[j] = 0;
      if (i == 4)
        solve();
      else
        gen(i + 1);
      Free[j] = 1;
    }
}
int main() {
  string s;
  cin >> s;
  int n = s.size();
  int p1, p2, p3, p4, p5 = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '1') p1 = i;
    if (s[i] == '6') p2 = i;
    if (s[i] == '8') p3 = i;
    if (s[i] == '9') p4 = i;
    if (s[i] == '0') p5++;
  }
  for (int i = 0; i < n; i++)
    if (i != p1 && i != p2 && i != p3 && i != p4 && s[i] != '0') {
      p = (p * 3 + s[i] - '0') % 7;
      cout << s[i];
    }
  memset(Free, 1, sizeof(Free));
  gen(1);
  for (int i = 1; i <= p5; i++) cout << "0";
}
