#include <bits/stdc++.h>
using namespace std;
int ar[10];
vector<int> vec;
vector<pair<int, int> > vecp;
int num[] = {1, 8, 6, 9};
int main() {
  string s;
  int zer = 0, n, m, n1 = 1, n6 = 6, n8 = 8, n9 = 9;
  cin >> s;
  while (next_permutation(num, num + 4))
    if (ar[(num[0] * 1000 + num[1] * 100 + num[2] * 10 + num[3]) % 7] == 0)
      ar[(num[0] * 1000 + num[1] * 100 + num[2] * 10 + num[3]) % 7] =
          num[0] * 1000 + num[1] * 100 + num[2] * 10 + num[3];
  n = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '0') {
      zer++;
      continue;
    }
    if (s[i] - 48 == n1)
      n1 = -1;
    else if (s[i] - 48 == n6)
      n6 = -1;
    else if (s[i] - 48 == n8)
      n8 = -1;
    else if (s[i] - 48 == n9)
      n9 = -1;
    else
      n = n * 10 + s[i] - 48, n %= 7, cout << s[i];
  }
  n = n * 10000;
  n = n % 7;
  cout << ar[(7 - n) % 7];
  for (int i = 0; i < zer; i++) cout << 0;
  return 0;
}
