#include <bits/stdc++.h>
using namespace std;
const int a[4] = {1, 6, 8, 9};
bool vis[4];
string M[7], ans;
char s[1000010];
void read(int &x) {
  char ch = getchar();
  int mark = 1;
  for (; ch != '-' && (ch < '0' || ch > '9'); ch = getchar())
    ;
  if (ch == '-') mark = -1, ch = getchar();
  for (x = 0; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - 48;
  x *= mark;
}
void dfs(int step, int x) {
  if (step == 5) {
    M[x] = ans;
    return;
  }
  string tmp = ans;
  for (int i = 0; i < 4; i++)
    if (!vis[i]) {
      vis[i] = 1;
      ans += (char)a[i] + 48;
      dfs(step + 1, (x * 10 + a[i]) % 7);
      vis[i] = 0;
      ans = tmp;
    }
}
int Get(char x) {
  if (x == 1 + 48) return 0;
  if (x == 6 + 48) return 1;
  if (x == 8 + 48) return 2;
  if (x == 9 + 48) return 3;
  return -1;
}
int main() {
  dfs(1, 0);
  scanf("%s", s);
  int l = strlen(s), x = 0;
  string A = "";
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i < l; i++)
    if (Get(s[i]) < 0 || vis[Get(s[i])]) {
      A += s[i];
      x = (x * 10 + s[i] - 48) % 7;
    } else
      vis[Get(s[i])] = 1;
  for (int i = 0; i < 7; i++) {
    int tmp = i;
    for (int j = 1; j <= l - 4; j++) tmp = (tmp * 10) % 7;
    if ((x + tmp) % 7 == 0) {
      cout << M[i] << A << endl;
      return 0;
    }
  }
  return 0;
}
