#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10;
char str[MAXN], res[MAXN],
    mdl[10][10] = {"1869", "1968", "1689", "6198", "8691", "8916", "8196"};
int num[15], p;
int main() {
  memset(num, 0, sizeof(num));
  scanf("%s", str);
  int len = strlen(str);
  for (int i = 0; i < len; i++) {
    int tmp = str[i] - '0';
    num[tmp]++;
  }
  p = 0;
  for (int i = 1; i <= 9; i++) {
    int tmp;
    if (i == 1 || i == 6 || i == 8 || i == 9)
      tmp = num[i] - 1;
    else
      tmp = num[i];
    for (int j = 0; j < tmp; j++) res[p + j] = i + '0';
    p += tmp;
  }
  int tmp = (10000) % 7, mod = 0;
  for (int i = 0; i < p; i++) {
    mod = (mod + (tmp % 7) * (res[i] - '0')) % 7;
    tmp = (tmp * 10) % 7;
  }
  for (int i = p - 1; i >= 0; i--) cout << res[i];
  for (int i = 0; i < 4; i++) cout << mdl[(7 - mod) % 7][i];
  for (int i = 0; i < num[0]; i++) cout << '0';
  cout << endl;
  return 0;
}
