#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
const int maxm = 1e3 + 5;
const int mod = 1e9 + 7;
const char a[7][5] = {"1869", "6198", "1896", "1689", "1986", "1968", "1698"};
char s[maxn];
bool vis[11];
inline void solve() {
  scanf("%s", s);
  int len = strlen(s);
  int p = 0, cnt = 0;
  for (int i = 0; i < len; i++) {
    if ((s[i] == '1' || s[i] == '6' || s[i] == '8' || s[i] == '9') &&
        !vis[s[i] - '0'])
      vis[s[i] - '0'] = 1;
    else if (s[i] == '0')
      cnt++;
    else {
      putchar(s[i]);
      p = (p * 10 + s[i] - '0') % 7;
    }
  }
  printf("%s", a[p]);
  for (int i = 0; i < cnt; i++) putchar('0');
}
int main() {
  solve();
  return 0;
}
