#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 11;
char str[N];
bool vis[N];
bool has[10];
char ss[5] = "1689";
int main() {
  scanf("%s", str);
  int len = strlen(str);
  int cnt = 0;
  int d = 0;
  for (int i = 0; i < len; ++i) {
    if (str[i] == '1' && !has[0]) {
      has[0] = true;
      vis[i] = true;
    } else if (str[i] == '6' && !has[1]) {
      has[1] = true;
      vis[i] = true;
    } else if (str[i] == '8' && !has[2]) {
      has[2] = true;
      vis[i] = true;
    } else if (str[i] == '9' && !has[3]) {
      has[3] = true;
      vis[i] = true;
    } else if (str[i] == '0') {
      has[4] = true;
      vis[i] = true;
      ++cnt;
    } else {
      d = (d * 10 + str[i] - '0') % 7;
    }
  }
  int s = 0;
  do {
    s = d;
    for (int i = 0; i < 4; ++i) s = (s * 10 + ss[i] - '0') % 7;
    if (s == 0) break;
  } while (next_permutation(ss, ss + 4));
  if (s % 7 != 0) {
    printf("0");
    return 0;
  }
  for (int i = 0; i < len; ++i)
    if (!vis[i]) printf("%c", str[i]);
  printf("%s", ss);
  while (cnt > 0) {
    printf("0");
    --cnt;
  }
  printf("\n");
}
