#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const int N = (int)1e6 + 7, mod = 1000000007, M = 2e9, lvl = 21;
char s[N];
int n, c[10], x[4] = {1, 6, 8, 9};
vector<int> base, a;
void push(int x) {
  a.push_back(x / 100);
  x %= 100;
  a.push_back(x / 10);
  x %= 10;
  a.push_back(x);
}
bool div7() {
  if (a.size() <= 4) {
    int ret = a.back();
    a.pop_back();
    if (a.empty()) return ret % 7 == 0;
    ret += a.back() * 10;
    a.pop_back();
    if (a.empty()) return ret % 7 == 0;
    ret += a.back() * 100;
    a.pop_back();
    if (a.empty()) return ret % 7 == 0;
    ret += a.back() * 1000;
    a.pop_back();
    if (a.empty()) return ret % 7 == 0;
  }
  int t = a.back() * 2, bg;
  a.pop_back();
  bg = a.back();
  a.pop_back();
  bg += a.back() * 10;
  a.pop_back();
  bg += a.back() * 100;
  a.pop_back();
  push(bg - t);
  return div7();
}
void print() {
  for (int i : base) printf("%d", i);
  for (int i = 0; i < 4; i++) printf("%d", x[i]);
  while (c[0]--) printf("0");
  exit(0);
}
int main() {
  scanf("%s", s);
  n = strlen(s);
  for (int i = 0; i < n; i++) c[s[i] - '0']++;
  c[1]--;
  c[6]--;
  c[8]--;
  c[9]--;
  for (int i = 1; i <= 9; i++) {
    while (c[i]--) base.push_back(i);
  }
  do {
    a.clear();
    for (int i : base) a.push_back(i);
    for (int i = 0; i < 4; i++) a.push_back(x[i]);
    if (div7()) print();
    n++;
  } while (next_permutation(x, x + 4));
  puts("0");
  return 0;
}
