#include <bits/stdc++.h>
using namespace std;
string s;
int n[11];
int main() {
  cin >> s;
  int len = s.length();
  for (int i = 0; i < len; i++) {
    n[s[i] - '0']++;
  }
  n[1]--;
  n[6]--;
  n[8]--;
  n[9]--;
  if (len - 4 == n[0]) {
    cout << 1869;
    for (int i = 0; i < n[0]; i++) cout << 0;
    return 0;
  }
  int t = 0;
  for (int i = 1; i < 10; i++) {
    while (n[i]--) {
      t = 10 * t + i;
      t %= 7;
      printf("%d", i);
    }
  }
  while (n[0]--) {
    t = 10 * t;
    t %= 7;
    printf("0");
  }
  switch (t) {
    case 1:
      cout << 6198;
      break;
    case 2:
      cout << 1896;
      break;
    case 3:
      cout << 6981;
      break;
    case 4:
      cout << 9168;
      break;
    case 5:
      cout << 6189;
      break;
    case 6:
      cout << 1698;
      break;
    case 0:
      cout << 1869;
      break;
  }
  return 0;
}
