#include <bits/stdc++.h>
using namespace std;
int arr[] = {1, 6, 8, 9}, rem[10];
void _print() {
  int p = arr[0] * 1000 + arr[1] * 100 + arr[2] * 10 + arr[3];
  rem[p % 7] = p;
}
void produce(int i) {
  int j;
  if (i == 4)
    _print();
  else {
    for (j = i; j < 4; j++) {
      swap(arr[i], arr[j]);
      produce(i + 1);
      swap(arr[i], arr[j]);
    }
  }
}
string s;
vector<int> A;
int main() {
  int i, j, k, cnt[10], temp, carry;
  produce(0);
  for (i = 0; i < 10; i++) cnt[i] = 0;
  cin >> s;
  for (i = 0; i < s.size(); i++) cnt[s[i] - '0']++;
  for (i = 0; i < 10; i++)
    if (i == 1 || i == 6 || i == 8 || i == 9) cnt[i]--;
  for (i = 1; i < 10; i++) {
    for (j = 0; j < cnt[i]; j++) A.push_back(i);
  }
  temp = 0;
  for (i = 0; i < A.size(); i++) {
    temp = temp * 10 + A[i];
    temp %= 7;
  }
  temp = (7 - (temp * 10000) % 7) % 7;
  A.push_back(rem[temp]);
  for (i = 0; i < A.size(); i++) printf("%d", A[i]);
  for (i = 0; i < cnt[0]; i++) printf("0");
  printf("\n");
  ;
  return 0;
}
