#include <bits/stdc++.h>
using namespace std;
int x, n, nr[14], j, i;
char s[1100000];
int main() {
  cin >> s;
  n = strlen(s);
  for (i = 0; i < n; ++i) nr[s[i] - '0']++;
  nr[1]--;
  nr[6]--;
  nr[8]--;
  nr[9]--;
  nr[0] += 4;
  x = 0;
  for (i = 1; i <= 9; ++i) {
    for (j = 1; j <= nr[i]; ++j) {
      x = x * 10 + i;
      x %= 7;
    }
  }
  for (i = 1; i <= 4; ++i) {
    x = x * 10;
    x %= 7;
  }
  for (i = 1; i <= 9; ++i) {
    for (j = 1; j <= nr[i]; ++j) cout << i;
  }
  if (x == 1) cout << 1896;
  if (x == 2) cout << 1986;
  if (x == 3) cout << 1698;
  if (x == 4) cout << 6198;
  if (x == 5) cout << 1689;
  if (x == 6) cout << 1968;
  if (x == 0) cout << 1869;
  for (i = 1; i <= nr[0] - 4; ++i) cout << 0;
  return 0;
}
