#include <bits/stdc++.h>
using namespace std;
int a[100005], b[5], i, m, ans, k, l, j, q, x, n, ma, mi;
string s;
int main() {
  cin >> s;
  for (i = 0; i < s.size(); i++) a[s[i] - '0']++;
  a[1]--;
  a[6]--;
  a[8]--;
  a[9]--;
  for (i = 1; i <= 9; i++)
    for (j = 0; j < a[i]; j++) cout << i;
  for (i = 1; i <= 9; i++)
    for (j = 0; j < a[i]; j++) ans = ans * 10 + i, ans %= 7;
  b[0] = 1;
  b[1] = 6;
  b[2] = 8;
  b[3] = 9;
  do {
    int res = ans;
    for (i = 0; i < 4; i++) res = res * 10 + b[i], res %= 7;
    if (res == 0) {
      cout << b[0] << b[1] << b[2] << b[3];
      break;
    }
  } while (next_permutation(b, b + 4));
  for (i = 0; i < a[0]; i++) cout << 0;
  cout << endl;
}
