#include <bits/stdc++.h>
using namespace std;
long const md = 1000000007;
long const mx = 2147483647;
long const mm = 1743;
long const maxN = 10000;
long const di[8] = {-1, 1, 0, 0, 1, -1, 1, -1};
long const dj[8] = {0, 0, 1, -1, 1, -1, -1, 1};
double const eps = 1e-6;
char c[1005000];
long n, i, j, m, k, l, a[1000500], b[10], x, y, d[1000500], f[10];
bool pr(long x) {
  long s = x;
  for (long i = 1; i <= l; i++) s = (s * 10 + d[i]) % 7;
  if (s == 0)
    return true;
  else
    return false;
}
void dfs(long f[], long j) {
  if (j == 4) {
    long k = ((f[0] * 10 + f[1]) * 10 + f[2]) * 10 + f[3];
    if (pr(k % 7)) {
      for (long i = 0; i < 4; i++) printf("%d", f[i]);
      for (long i = 1; i <= l; i++) printf("%d", d[i]);
      exit(0);
    }
    return;
  }
  for (long i = 1; i <= 4; i++)
    if (b[i] == 0) {
      b[i] = 1;
      f[j] = a[i];
      dfs(f, j + 1);
      b[i] = 0;
    }
}
int main() {
  scanf("%s", c);
  n = strlen(c);
  for (i = 0; i < n; i++) a[i] = c[i] - '0';
  l = 0;
  for (i = 0; i < n; i++)
    if ((a[i] == 1 || a[i] == 6 || a[i] == 8 || a[i] == 9) && b[a[i]] == 0)
      b[a[i]] = 1;
    else
      d[++l] = a[i];
  x = 0;
  a[1] = 1;
  a[2] = 6;
  a[3] = 8;
  a[4] = 9;
  for (i = 1; i <= l; i++) x = (x * 10 + d[i]) % 7;
  for (i = 1; i <= 6; i++) b[i] = 0;
  dfs(f, 0);
  printf("0");
}
