#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int a[10];
  memset(a, 0, sizeof(a));
  for (int i = 0; i < s.size(); i++) {
    a[s[i] - '0']++;
  }
  a[1]--;
  a[6]--;
  a[8]--;
  a[9]--;
  int val = 1;
  for (int i = 0; i < s.size() - 4; i++) {
    val = val * 10;
    val = val % 7;
  }
  int vv = 1;
  int v = 0;
  for (int i = 0; i <= 9; i++) {
    for (int j = 0; j < a[i]; j++) {
      v = (v * 10 + i) % 7;
    }
  }
  int ar[] = {1, 6, 8, 9};
  do {
    int sum = 0;
    for (int i = 0; i < 4; i++) {
      int v1 = 1;
      for (int j = 0; j < 3 - i; j++) {
        v1 = v1 * 10;
      }
      v1 = v1 * ar[i];
      sum += v1;
    }
    sum = (sum * val) % 7;
    sum += v;
    sum %= 7;
    if (!sum) {
      for (int i = 0; i < 4; i++) {
        cout << ar[i];
      }
      for (int i = 0; i <= 9; i++) {
        for (int j = 0; j < a[i]; j++) {
          cout << i;
        }
      }
      cout << endl;
      return 0;
    }
  } while (next_permutation(ar, ar + 4));
}
