#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, sz;
  string s;
  cin >> s;
  string s1 = "";
  i = 0;
  sz = s.size();
  string s2 = "1689";
  bool vst[20];
  memset((vst), (0), sizeof(vst));
  for (i = 0; i < sz; i++) {
    if (s[i] == '1') {
      if (vst[1])
        s1 += s[i];
      else
        vst[1] = 1;
    } else if (s[i] == '6') {
      if (vst[6])
        s1 += s[i];
      else
        vst[6] = 1;
    } else if (s[i] == '8') {
      if (vst[8])
        s1 += s[i];
      else
        vst[8] = 1;
    } else if (s[i] == '9') {
      if (vst[9])
        s1 += s[i];
      else
        vst[9] = 1;
    } else
      s1 += s[i];
  }
  sz = s1.size();
  long long ans = 0;
  for (i = 0; i < sz; i++) {
    ans *= 10;
    ans += (s1[i] - '0');
    ans %= 7;
  }
  long long m = 1;
  for (i = 0; i < s.size() - 4; i++) {
    m *= 10;
    m %= 7;
  }
  sort((s2).begin(), (s2).end());
  do {
    long long tans = 0;
    for (i = 0; i < s2.size(); i++) {
      tans = tans * 10;
      tans += (s2[i] - '0');
      tans %= 7;
    }
    if ((ans + tans * m) % 7 == 0) {
      string s3 = s2 + s1;
      long long v = 0;
      for (i = 0; i < s3.size(); i++) {
        v = v * 10 + s3[i] - '0';
        v %= 7;
      }
      assert(v == 0);
      cout << s3 << endl;
      return 0;
    }
  } while (next_permutation((s2).begin(), (s2).end()));
  cout << 0 << endl;
  return 0;
}
