#include<bits/stdc++.h>
using namespace std;
using std::string;
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define FORI(i,n) for(int (i)=1;(i)<=(n);++(i))
//#define mod 1000000007
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define bitcount __builtin_popcount
#define all(v) v.begin(),v.end()
#define mem(n,m) memset(n,m,sizeof(n))
#define pii pair<int,int>
#define pll pair<long long,long long>
#define sii set<int>
#define sll set<long long>
#define vii vector<int>
#define vll vector<long long>
#define mii map<int,int>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define EPSILON 1e-9
#define MAX 100002
#define PI 3.1415926535897932384626433832795028841971693993751
typedef long long  ll;
typedef unsigned long long llu;
typedef long double  ldb;
typedef double  db ;
string ans;
int cnt[10];
void string_add(int n)
{
    string t;
    while(n)
    {
        t+=n%10+'0';
        n/=10;
    }
    reverse(t.begin(),t.end());
    ans+=t;
}
void find_string(int mod)
{
    if(mod==0)
        string_add(1869);
    if(mod==1)
        string_add(1968);
    if(mod==2)
        string_add(9186);
    if(mod==3)
        string_add(1689);
    if(mod==4)
        string_add(1698);
    if(mod==5)
        string_add(9168);
    if(mod==6)
        string_add(1896);

}
int main()
{
    //freopen("in.txt","r",stdin);
    string s;
    cin>>s;
    int c=0;
    for(int i=0;i<s.size();i++)
    {
        int n=(s[i]-'0');
        if(n==1&&cnt[1]==0)
       {
           cnt[1]++;
           continue;
       }
        else if(n==6&&cnt[6]==0)
       {
           cnt[6]++;
           continue;
       }
         else if(n==8&&cnt[8]==0)
        {
             cnt[8]++;
            continue;
        }
         else if(n==9&&cnt[9]==0)
        {
             cnt[9]++;
            continue;
        }
         else if(n==0)
        {
             cnt[0]++;
            continue;
        }
         n=c*10+n;
         if(n<7)
         {
             c=n;
             ans+=s[i];
         }
        else if(n>=7)
         {
             c=n%7;
             ans+=s[i];
         }

    }
    find_string(c);
    while(cnt[0]--)
    {
        ans+='0';
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
using std::string;
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define FORI(i,n) for(int (i)=1;(i)<=(n);++(i))
//#define mod 1000000007
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define bitcount __builtin_popcount
#define all(v) v.begin(),v.end()
#define mem(n,m) memset(n,m,sizeof(n))
#define pii pair<int,int>
#define pll pair<long long,long long>
#define sii set<int>
#define sll set<long long>
#define vii vector<int>
#define vll vector<long long>
#define mii map<int,int>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define EPSILON 1e-9
#define MAX 100002
#define PI 3.1415926535897932384626433832795028841971693993751
typedef long long  ll;
typedef unsigned long long llu;
typedef long double  ldb;
typedef double  db ;
string ans;
int cnt[10];
void string_add(int n)
{
    string t;
    while(n)
    {
        t+=n%10+'0';
        n/=10;
    }
    reverse(t.begin(),t.end());
    ans+=t;
}
void find_string(int mod)
{
    if(mod==0)
        string_add(1869);
    if(mod==1)
        string_add(1968);
    if(mod==2)
        string_add(9186);
    if(mod==3)
        string_add(6198);
    if(mod==4)
        string_add(1698);
    if(mod==5)
        string_add(9168);
    if(mod==6)
        string_add(1896);

}
int main()
{
    //freopen("in.txt","r",stdin);
    string s;
    cin>>s;
    int c=0;
    for(int i=0;i<s.size();i++)
    {
        int n=c*10+(s[i]-'0');
        if(n==1&&cnt[1]==0)
       {
           cnt[1]++;
           continue;
       }
        else if(n==6&&cnt[6]==0)
       {
           cnt[6]++;
           continue;
       }
         else if(n==8&&cnt[8]==0)
        {
             cnt[8]++;
            continue;
        }
         else if(n==9&&cnt[9]==0)
        {
             cnt[9]++;
            continue;
        }
         else if(n==0&&cnt[0]==0)
        {
             cnt[0]++;
            continue;
        }
        else if(n<7)
         {
             c=n;
             ans+=s[i];
         }
        else if(n>=7)
         {
             c=n%7;
             ans+=s[i];
         }

    }
    find_string(c);
    while(cnt[0]--)
    {
        ans+='0';
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
using std::string;
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define FORI(i,n) for(int (i)=1;(i)<=(n);++(i))
//#define mod 1000000007
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define bitcount __builtin_popcount
#define all(v) v.begin(),v.end()
#define mem(n,m) memset(n,m,sizeof(n))
#define pii pair<int,int>
#define pll pair<long long,long long>
#define sii set<int>
#define sll set<long long>
#define vii vector<int>
#define vll vector<long long>
#define mii map<int,int>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define EPSILON 1e-9
#define MAX 100002
#define PI 3.1415926535897932384626433832795028841971693993751
typedef long long  ll;
typedef unsigned long long llu;
typedef long double  ldb;
typedef double  db ;
string ans;
int cnt[10];
void string_add(int n)
{
    string t;
    while(n)
    {
        t+=n%10+'0';
        n/=10;
    }
    reverse(t.begin(),t.end());
    ans+=t;
}
void find_string(int mod)
{
    if(mod==7)
        string_add(1869);
    if(mod==1)
        string_add(1968);
    if(mod==2)
        string_add(9186);
    if(mod==3)
        string_add(1689);
    if(mod==4)
        string_add(1698);
    if(mod==5)
        string_add(1986);
    if(mod==6)
        string_add(1896);

}
int main()
{
  //  freopen("in.txt","r",stdin);
    string s;
    cin>>s;
    int c=0;
    for(int i=0;i<s.size();i++)
    {
        int n=(s[i]-'0');
        if(n==1&&cnt[1]==0)
       {
           cnt[1]++;
           continue;
       }
        else if(n==6&&cnt[6]==0)
       {
           cnt[6]++;
           continue;
       }
         else if(n==8&&cnt[8]==0)
        {
             cnt[8]++;
            continue;
        }
         else if(n==9&&cnt[9]==0)
        {
             cnt[9]++;
            continue;
        }
         else if(n==0)
        {
             cnt[0]++;
            continue;
        }
         n=c*10+n;
         if(n<7)
         {
             c=n;
             ans+=s[i];
         }
        else if(n>=7)
         {
             c=n%7;
             ans+=s[i];
         }

    }//cout<<"c"<<c<<endl;
    find_string(7-(c*10000)%7);
    while(cnt[0]--)
    {
        ans+='0';
    }
    cout<<ans<<endl;
}


#include <cstring>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>

#define REP(i,n) for(int i=0;i<n;i++)

using namespace std;
char a[1000001],b[1000001];
int nol,now;
bool flag[10],bc,ada;
string c;
long long jawab,tmpp;
string nols;

bool cek(string qq) {
long long tmpq;
int jawab2;
    jawab2=0;
//  1689
//  1 18 16 54
    for (int i=0;i<4;i++) {
        tmpq=((i+nol+1) % 6);
        if (tmpq == 1) {
            int q=(qq[i]- '0')*1;
        //  cout << q <<" "<< qq[i] <<endl;
            jawab2=jawab2+q;
        }else if (tmpq == 2) {
            int q=(qq[i]- '0')*3;
        //  cout << q <<" "<< qq[i] <<endl;
            jawab2=jawab2+q;
        }else if (tmpq == 3) {
            int q=(qq[i]- '0')*2;
        //  cout << q <<" "<< qq[i] <<endl;
            jawab2=jawab2+q;
        }else if (tmpq == 4) {
            int q=(qq[i]- '0')*6;
        //  cout << q <<" "<< qq[i] <<endl;
            jawab2=jawab2+q;
        }else if (tmpq == 5) {
            int q=(qq[i]- '0')*4;
        //  cout << q <<" "<< qq[i] <<endl;
            jawab2=jawab2+q;
        }else if (tmpq == 0) {
            int q=(qq[i]- '0')*5;
        //  cout << q <<" "<< qq[i] <<endl;
            jawab2=jawab2+q;
        }
    }
    if ((jawab2+jawab) % 7 == 0 ) {
//      cout <<"jawab "<<jawab2<<" "<<jawab <<" "<<qq<<endl;
        return true;
    }else {
        return false;
    }
}

int main(){
    gets(a);
    now=0;
    for (int i=0;i<strlen(a);i++) {
        bc=true;
        if ((a[i]=='1')&&(flag[1]==false)) {
            flag[1]=true;
            bc=false;
        }else
        if ((a[i]=='6')&&(flag[6]==false)) {
            flag[6]=true;
            bc=false;
        }else
        if ((a[i]=='8')&&(flag[8]==false)) {
            flag[8]=true;
            bc=false;
        }else
        if ((a[i]=='9')&&(flag[9]==false)) {
            flag[9]=true;
            bc=false;
        }else
        if (a[i]=='0') {
            bc=false;
            nol++;
        }
        if (bc==true) {
            b[now]=a[i];
            now++;
        }
    }
    for (int i=0;i<now;i++) {
        tmpp=((strlen(a)-i) % 6);
        if (tmpp == 1) {
            int q=(b[i] - '0')*1;
    //      cout << q << " "<<b[i]<<endl;
            jawab=jawab+q;
        }else if (tmpp == 2) {
            int q=(b[i] - '0')*3;
    //      cout << q << " "<<b[i]<<endl;
            jawab=jawab+q;
        }else if (tmpp == 3) {
            int q=(b[i] - '0')*2;
    //      cout << q << " "<<b[i]<<endl;
            jawab=jawab+q;
        }else if (tmpp == 4) {
            int q=(b[i] - '0')*6;
    //      cout << q << " "<<b[i]<<endl;
            jawab=jawab+q;
        }else if (tmpp == 5) {
            int q=(b[i] - '0')*4;
    //      cout << q << " "<<b[i]<<endl;
            jawab=jawab+q;
        }else if (tmpp == 0) {
            int q=(b[i] - '0')*5;
    //      cout << q << " "<<b[i]<<endl;
            jawab=jawab+q;
        }
    }
//  cout << jawab <<endl;
//  cout << strlen(b) <<endl;
    c="1689";
    for (int i=0;i<nol;i++) {
        nols=nols+'0';
    }
    do {
        if ((cek(c)==true)) {
            ada=true;
            printf("%s",b);
            for (int i=c.length()-1;i>=0;i--) {
                printf("%c",c[i]);
            }
            for (int i=0;i<nol;i++) {
                printf("0");
            }
            printf("\n");
            break;
        }
    }while(next_permutation(c.begin(),c.end()));
    if (ada==false) {
        printf("0\n");
    }
}


#include <cstring>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>

#define REP(i,n) for(int i=0;i<n;i++)

using namespace std;
string a;
int nol,now;
bool flag[10],bc,ada;
string c;
long long jawab,tmpp;
string nols;

int main(){
	cin >> a;
	now=0;
	a.erase(find(a.begin(),a.end(),'1'));
	a.erase(find(a.begin(),a.end(),'6'));
	a.erase(find(a.begin(),a.end(),'8'));
	a.erase(find(a.begin(),a.end(),'9'));

	nol = count(a.begin(),a.end(),'0');
	if (a.length()==nol) {
		cout << "1869";
		for (int i=0;i<nol;i++) {
			printf("0");
		}
		printf("\n");
		return 0;
	}
	for (int i=0;i<nol;i++) {
		a.erase(find(a.begin(),a.end(),'0'));
	}

	c="1689";
	for (int i=0;i<nol;i++) {
		nols=nols+'0';
	}
	ada=false;
	do {
//		cout <<"Aa"<<endl;
		string q = a + c;
		int t=0;
		for (int i=0;i<q.length();i++) {
			t = t*10 + (q[i] - '0');
			t %=7;
		}
		if (t==0) {
			cout << q << nols <<endl;
			ada=true;
			return 0;
		}
	}while(next_permutation(c.begin(),c.end()));
	if (ada==false) {
		printf("0\n");
	}
}


#include <cstring>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>

#define REP(i,n) for(int i=0;i<n;i++)

using namespace std;
string a;
int nol,now;
bool flag[10],bc,ada;
string c;
long long jawab,tmpp;
string nols;

int main(){
	cin >> a;
	now=0;
	a.erase(find(a.begin(),a.end(),'1'));
	a.erase(find(a.begin(),a.end(),'6'));
	a.erase(find(a.begin(),a.end(),'8'));
	a.erase(find(a.begin(),a.end(),'9'));

	nol = count(a.begin(),a.end(),'0');
	for (int i=0;i<nol;i++) {
		a.erase(find(a.begin(),a.end(),'0'));
	}

	c="1689";
	for (int i=0;i<nol;i++) {
		nols=nols+'0';
	}
	ada=false;
	do {
		string q = a + c;
		int t=0;
		for (int i=0;i<q.length();i++) {
			t = t*10 + (q[i] - '0');
			t %=7;
		}
		if (t==0) {
			cout << q << nols <<endl;
			ada=true;
			break;
		}
	}while(next_permutation(c.begin(),c.end()));
	if (ada==false) {
		printf("0\n");
	}
}


#include <cstring>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>

#define REP(i,n) for(int i=0;i<n;i++)

using namespace std;
string a;
int nol,now;
bool flag[10],bc,ada;
string c;
long long jawab,tmpp;
string nols;

int main(){
	cin >> a;
	now=0;
	a.erase(find(a.begin(),a.end(),'1'));
	a.erase(find(a.begin(),a.end(),'6'));
	a.erase(find(a.begin(),a.end(),'8'));
	a.erase(find(a.begin(),a.end(),'9'));

	nol = count(a.begin(),a.end(),'0');
	if (a.length()==nol) {
		cout << "1869";
		for (int i=0;i<nol;i++) {
			printf("0");
		}
		printf("\n");
		return 0;
	}

	c="1689";

	sort(a.rbegin(),a.rend());

	ada=false;
	do {
//		cout <<"Aa"<<endl;
		string q = a + c;
		int t=0;
		for (int i=0;i<q.length();i++) {
			t = t*10 + (q[i] - '0');
			t %=7;
		}
		if (t==0) {
			cout << q <<endl;
			ada=true;
			return 0;
		}
	}while(next_permutation(c.begin(),c.end()));
	if (ada==false) {
		printf("0\n");
	}
}


#include <cstring>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>

#define REP(i,n) for(int i=0;i<n;i++)

using namespace std;
string a;
int nol,now;
bool flag[10],bc,ada;
string c;
long long jawab,tmpp;
string nols;

int main(){
	cin >> a;
	now=0;
	a.erase(find(a.begin(),a.end(),'1'));
	a.erase(find(a.begin(),a.end(),'6'));
	a.erase(find(a.begin(),a.end(),'8'));
	a.erase(find(a.begin(),a.end(),'9'));

	nol = count(a.begin(),a.end(),'0');
	if (a.length()==nol) {
		cout << "1869";
		for (int i=0;i<nol;i++) {
			printf("0");
		}
		printf("\n");
		return 0;
	}
	for (int i=0;i<nol;i++) {
		a.erase(find(a.begin(),a.end(),'0'));
	}

	c="1689";
	for (int i=0;i<nol;i++) {
		nols=nols+'0';
	}
	ada=false;
	do {
		cout <<"Aa"<<endl;
		string q = a + c;
		int t=0;
		for (int i=0;i<q.length();i++) {
			t = t*10 + (q[i] - '0');
			t %=7;
		}
		if (t==0) {
			cout << q << nols <<endl;
			ada=true;
			return 0;
		}
	}while(next_permutation(c.begin(),c.end()));
	if (ada==false) {
		printf("0\n");
	}
}


#include <cstring>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>

#define REP(i,n) for(int i=0;i<n;i++)

using namespace std;
char a[1000001],b[1000001];
int nol,now;
bool flag[10],bc,ada;
string c;
long long jawab,tmpp;
string nols;

int main(){
	gets(a);
	now=0;
	for (int i=0;i<strlen(a);i++) {
		bc=true;
		if ((a[i]=='1')&&(flag[1]==false)) {
			flag[1]=true;
			bc=false;
		}else
		if ((a[i]=='6')&&(flag[6]==false)) {
			flag[6]=true;
			bc=false;
		}else
		if ((a[i]=='8')&&(flag[8]==false)) {
			flag[8]=true;
			bc=false;
		}else
		if ((a[i]=='9')&&(flag[9]==false)) {
			flag[9]=true;
			bc=false;
		}else
		if (a[i]=='0') {
			bc=false;
			nol++;
		}
		if (bc==true) {
			b[now]=a[i];
			now++;
		}
	}

	c="1689";
	for (int i=0;i<nol;i++) {
		nols=nols+'0';
	}
	ada=false;
	do {
		string q = b + c;
		int t=0;
		for (int i=0;i<q.length();i++) {
			t = t*10 + (q[i] - '0');
			t %=7;
		}
		if (t==0) {
			cout << q << nols <<endl;
			ada=true;
			break;
		}
	}while(next_permutation(c.begin(),c.end()));
	if (ada==false) {
		printf("0\n");
	}
}


#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <math.h>
#include <iostream>
#include <queue>

using namespace std;

const int Remain[7] = {1869, 1968, 1689, 6198, 1698, 1986, 1896};
const int MAXN = 1e6 + 10;

char s[MAXN];
int sum[MAXN];

int init()
{
          while (scanf("%s", &s) != EOF)
          {
                    memset(sum, 0, sizeof(sum));
                    for (int i = 0; i < strlen(s); i++)
                    sum[s[i] - '0']++;
                    sum[1]--; sum[6]--; sum[8]--; sum[9]--;
                    int t = 0;
                    for (int i = 1; i <= 9; i++)
                    for (int j = 1; j <= sum[i]; j++)
                    {
                              printf("%d", i);
                              t = (10 * t + i) % 7;
                    }
                    printf("%d", Remain[(7-(t*10000) % 7) % 7]);
                    for (int i = 1; i <= sum[0]; i++) printf("0");
                    printf("\n");
          }
	return 0;
}

int main()
{
          //freopen("in.txt", "r", stdin);
	init();
	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <math.h>
#include <iostream>
#include <queue>

using namespace std;

const int Remain[7] = {1869, 1968, 1689, 6198, 1698, 1986, 1896};
const int MAXN = 1e6 + 10;

char s[MAXN];
//int sum[MAXN];

int init()
{
          while (scanf("%s", &s) != EOF)
          {
                    //memset(sum, 0, sizeof(sum));
                    int ok1,ok2,ok3,ok4,a,num0,t;
                    ok1=ok2=ok3=ok4=t=num0=0;
                    for (int i = 0; i < strlen(s); i++)
                    {
                              a = s[i] - '0';
                              if (!ok1 && a == 1) { ok1 = 1; continue;}
                              if (!ok2 && a == 2) { ok2 = 1; continue;}
                              if (!ok3 && a == 3) { ok3 = 1; continue;}
                              if (!ok4 && a == 4) { ok4 = 1; continue;}
                              if (a==0) { num0++; continue;}
                              t = (t*10+a)%7;
                              printf("%d", a);
                    }
                    printf("%d", Remain[(7-(t*10000) % 7) % 7]);
                    for (int i = 1; i <= num0; i++) printf("0");
                    printf("\n");
          }
	return 0;
}

int main()
{
          //freopen("in.txt", "r", stdin);
	init();
	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <math.h>
#include <iostream>
#include <queue>

using namespace std;

const int Remain[7] = {1869, 1968, 1689, 6198, 1698, 1986, 1896};
const int MAXN = 1e6 + 10;

char s[MAXN];
//int sum[MAXN];

int init()
{
          while (scanf("%s", &s) != EOF)
          {
                    //memset(sum, 0, sizeof(sum));
                    int ok1,ok2,ok3,ok4,a,num0,t;
                    ok1=ok2=ok3=ok4=t=num0=0;
                    for (int i = 0; i < strlen(s); i++)
                    {
                              a = s[i] - '0';
                              if (!ok1 && a == 1) { ok1 = 1; continue;}
                              if (!ok2 && a == 6) { ok2 = 1; continue;}
                              if (!ok3 && a == 8) { ok3 = 1; continue;}
                              if (!ok4 && a == 9) { ok4 = 1; continue;}
                              if (a==0) { num0++; continue;}
                              t = (t*10+a)%7;
                              printf("%d", a);
                    }
                    printf("%d", Remain[(7-(t*10000) % 7) % 7]);
                    for (int i = 1; i <= num0; i++) printf("0");
                    printf("\n");
          }
	return 0;
}

int main()
{
          //freopen("in.txt", "r", stdin);
	init();
	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <math.h>
#include <iostream>
#include <queue>

using namespace std;

const int Remain[7] = {1869, 1968, 1689, 6198, 1698, 1986, 1896};
const int MAXN = 1e6 + 10;

char s[MAXN];
//int sum[MAXN];

int init()
{
          while (scanf("%s", &s) != EOF)
          {
                    //memset(sum, 0, sizeof(sum));
                    int ok1,ok2,ok3,ok4,a,num0,t;
                    ok1=ok2=ok3=ok4=t=num0=0;
                    int len = strlen(s);
                    for (int i = 0; i < len; i++)
                    {
                              a = s[i] - '0';
                              if (!ok1 && a == 1) { ok1 = 1; continue;}
                              if (!ok2 && a == 6) { ok2 = 1; continue;}
                              if (!ok3 && a == 8) { ok3 = 1; continue;}
                              if (!ok4 && a == 9) { ok4 = 1; continue;}
                              if (a==0) { num0++; continue;}
                              t = (t*10+a)%7;
                              printf("%d", a);
                    }
                    printf("%d", Remain[(7-(t*10000) % 7) % 7]);
                    for (int i = 1; i <= num0; i++) printf("0");
                    printf("\n");
          }
	return 0;
}

int main()
{
          //freopen("in.txt", "r", stdin);
	init();
	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <math.h>
#include <iostream>
#include <queue>

using namespace std;

const int Remain[7] = {1869, 1968, 1689, 6198, 1698, 1986, 1896};
const int MAXN = 1e6 + 10;

char s[MAXN];
int sum[MAXN];

int init()
{
          while (scanf("%s", &s) != EOF)
          {
                    memset(sum, 0, sizeof(sum));
                    for (int i = 0; i < strlen(s); i++)
                    sum[s[i] - '0']++;
                    sum[1]--; sum[6]--; sum[8]--; sum[9]--;
                    int t = 0;
                    for (int i = 1; i <= 9; i++)
                    {
                    for (int j = 1; j <= sum[i]%6; j++)
                    {
                              t = (10 * t + i) % 7;
                    }
                    for (int j = 1; j <= sum[i]; j++) printf("%d", i);
                    }
                    printf("%d", Remain[(7-(t*10000) % 7) % 7]);
                    for (int i = 1; i <= sum[0]; i++) printf("0");
                    printf("\n");
          }
	return 0;
}

int main()
{
          //freopen("in.txt", "r", stdin);
	init();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1000010;
int cloc,len,len2,len3;
int a[N],b[N],c[N];
bool mp[101];
char s[N];
void jian(){
	b[len2]=b[len2]-c[1];
	for (int i=1; b[i]<0; i++) b[i]+=10,b[i+1]--;
}
bool check(){
	for (int i=1; i<=len; i++) b[i]=a[i]; len2=len;
	while (len2>2){
		len3=1;
		c[len3]=b[len2];
		len2--;
		jian();
		jian();
	}
	if (mp[b[1]*10+b[2]]) return 1;
	return 0;
}
void write(){
	for (int i=1; i<=len; i++) printf("%d",a[i]);
	exit(0);
}
int main(){
	srand(1869);
	scanf("%s",s+1);
	len=strlen(s+1);
	for (int i=1; i*7<100; i++) mp[i*7]=1;
	for (int i=1; s[i]; i++) a[i]=s[i]-48;
	if (check()) write();
	while (1){
		++cloc;
		int i=rand()%len+1;
		int j=rand()%len+1;
		swap(a[i],a[j]);
		if (a[1]&&check()) write();
		if (cloc>11000) {printf("0"); break;}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1000010;
int cloc,len,len2,len3,tot;
int a[N],b[N],c[N],v[10],k[10],mp[10][10],kk[10];
bool bb[10];
char s[N];
bool check(){
	int x=0;
	for (int i=1; i<=len; i++)
	x=(x*10+a[i])%7;
	if (x==0) return 1; else return 0;
}
void gouzao(int x){
	if (x==5){
		++tot;
		for (int i=1; i<=4; i++) mp[tot][i]=k[v[i]];
		return;
	}
	for (int i=1; i<=4; i++) if (!bb[i]) {
		bb[i]=1;
		v[x]=i;
		gouzao(x+1);
		bb[i]=0;
	}
}
void write(){
	for (int i=1; i<=len; i++) printf("%d",a[i]);
	exit(0);
}
void del(int x){
	for (int i=x; i>=1; i--) a[i]=a[i-1];
}
int main(){
	k[1]=1; k[2]=6; k[3]=8; k[4]=9;
	gouzao(1);
	scanf("%s",s+1);
	len=strlen(s+1);
	for (int i=1; s[i]; i++) a[i]=s[i]-48;
	for (int i=1; i<=len; i++) if (a[i]==1) {del(i); break;}
	for (int i=1; i<=len; i++) if (a[i]==6) {del(i); break;}
	for (int i=1; i<=len; i++) if (a[i]==8) {del(i); break;}
	for (int i=1; i<=len; i++) if (a[i]==9) {del(i); break;}
	for (int i=1; i<=24; i++){
		for (int j=1; j<=4; j++) a[j]=mp[i][j];
		if (check()) write();
	}
	printf("0");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1000010;
int cloc,len,len2,len3;
int a[N],b[N],c[N];
bool mp[10001];
char s[N];
bool check(){
	int x=0;
	for (int i=1; i<=len; i++)
	x=(x*10+a[i])%7;
	if (x==0) return 1; else return 0;
}
void write(){
	for (int i=1; i<=len; i++) printf("%d",a[i]);
	exit(0);
}
int main(){
	srand(613);
	scanf("%s",s+1);
	len=strlen(s+1);
	for (int i=1; s[i]; i++) a[i]=s[i]-48;
	if (check()) write();
	while (1){
		++cloc;
		int i=rand()%len+1;
		int j=rand()%len+1;
		if (a[i]==a[j]) continue;
		swap(a[i],a[j]);
		if (a[1]&&check()) write();
		if (cloc>100) {printf("0"); break;}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1000010;
int cloc,len,len2,len3;
int a[N],b[N],c[N];
bool mp[10001];
char s[N];
bool check(){
	int x=0;
	for (int i=1; i<=len; i++)
	x=(x*10+a[i])%7;
	if (x==0) return 1; else return 0;
}
void write(){
	for (int i=1; i<=len; i++) printf("%d",a[i]);
	exit(0);
}
int main(){
	srand(613);
	scanf("%s",s+1);
	len=strlen(s+1);
	for (int i=1; s[i]; i++) a[i]=s[i]-48;
	if (check()) write();
	while (1){
		++cloc;
		int i=rand()%len+1;
		int j=rand()%len+1;
		swap(a[i],a[j]);
		if (a[1]&&check()) write();
		if (cloc>100) {printf("0"); break;}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1000010;
int cloc,len,len2,len3;
int a[N],b[N],c[N];
bool mp[101];
char s[N];
void jian(){
	b[len2]=b[len2]-c[1];
	for (int i=1; b[i]<0; i++) b[i]+=10,b[i+1]--;
}
bool check(){
	for (int i=1; i<=len; i++) b[i]=a[i]; len2=len;
	while (len2>2){
		len3=1;
		c[len3]=b[len2];
		len2--;
		jian();
		jian();
	}
	if (mp[b[1]*10+b[2]]) return 1;
	return 0;
}
void write(){
	for (int i=1; i<=len; i++) printf("%d",a[i]);
	exit(0);
}
int main(){
	srand(7553);
	scanf("%s",s+1);
	len=strlen(s+1);
	for (int i=1; i*7<100; i++) mp[i*7]=1;
	for (int i=1; s[i]; i++) a[i]=s[i]-48;
	if (check()) write();
	while (1){
		++cloc;
		int i=rand()%len+1;
		int j=rand()%len+1;
		swap(a[i],a[j]);
		if (a[len]&&check()) write();
		swap(a[i],a[j]);
		//if (cloc>1100) {printf("0"); break;}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1000010;
int cloc,len,len2,len3;
int a[N],b[N],c[N];
bool mp[101];
char s[N];
void jian(){
	b[len2]=b[len2]-c[1];
	for (int i=1; b[i]<0; i++) b[i]+=10,b[i+1]--;
}
bool check(){
	for (int i=1; i<=len; i++) b[i]=a[i]; len2=len;
	while (len2>2){
		len3=1;
		c[len3]=b[len2];
		len2--;
		jian();
		jian();
	}
	if (mp[b[1]*10+b[2]]) return 1;
	return 0;
}
void write(){
	for (int i=1; i<=len; i++) printf("%d",a[i]);
	exit(0);
}
int main(){
	srand(1869);
	scanf("%s",s+1);
	len=strlen(s+1);
	for (int i=1; i*7<100; i++) mp[i*7]=1;
	for (int i=1; s[i]; i++) a[i]=s[i]-48;
	if (check()) write();
	while (1){
		++cloc;
		int i=rand()%len+1;
		int j=rand()%len+1;
		swap(a[i],a[j]);
		if (a[len]&&check()) write();
		if (cloc>11000) {printf("0"); break;}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1000010;
int cloc,len,len2,len3;
int a[N],b[N],c[N];
bool mp[10001];
char s[N];
bool check(){
	int x=0;
	for (int i=1; i<=len; i++)
	x=(x*10+a[i])%7;
	if (x==0) return 1; else return 0;
}
void write(){
	for (int i=1; i<=len; i++) printf("%d",a[i]);
	exit(0);
}
int main(){
	srand(1869);
	scanf("%s",s+1);
	len=strlen(s+1);
	for (int i=1; s[i]; i++) a[i]=s[i]-48;
	if (check()) write();
	while (1){
		++cloc;
		int i=rand()%len+1;
		int j=rand()%len+1;
		swap(a[i],a[j]);
		if (a[1]&&check()) write();
		if (cloc>11000) {printf("0"); break;}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define MOD3 1000000000
#define MOD2 998244353
float PHI = 1.6180339;
const float  PI_F=3.14159265358979f;
#define MAX 1000 m
#define endl "\n"
#define manhunt 32
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define PI 3.1415926535897932384626433
//typedef long long float;
#define int long long
//#define double long long
typedef pair<int, int> pii;
//#define float unsigned long long
typedef pair<int, int> pii;
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define CHAR_SIZE 26
#define pi pair<int,int>

int modpow(int x, int n, int m) { if (n == 0) return 1%m; long long u = modpow(x,n/2,m); u = (u*u)%m; if (n%2 == 1) u = (u*x)%m; return u; }

int add(int x, int y)
{
	x += y;
	if (x >= MOD2) return x - MOD2;
	return x;
}
int sub(int x, int y)
{
	x -= y;
	if (x < 0) return x + MOD2;
	return x;
}
int inv(int a, int m = MOD2)
{
	return modpow(a, m - 2, m);
}
int mul(int a, int b)
{
	return (long long) a * b % MOD2;
}

int nCrModp(int n, int r, int p)
{
    int C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;
    for (int i = 1; i <= n; i++)
    {
        for (int j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1])%p;
    }
    return C[r];
}

/*
Link : https://github.com/ngthanhtrung23/ACM_Notebook_new/blob/master/Math/bigint.h
Fixed BigInt operator/ function bug where it coudn't calculate a / b if a was zero so added a condition for when a == 0;
*/
const int BASE_DIGITS = 9;
const int BASE = 1000000000;
struct BigInt {
    int sign;
    vector<int> a;

    // -------------------- Constructors --------------------
    // Default constructor.
    BigInt() : sign(1) {}

    // Constructor from long long.
    BigInt(long long v) {
        *this = v;
    }
    BigInt& operator = (long long v) {
        sign = 1;
        if (v < 0) {
            sign = -1;
            v = -v;
        }
        a.clear();
        for (; v > 0; v = v / BASE)
            a.push_back(v % BASE);
        return *this;
    }

    // Initialize from string.
    BigInt(const string& s) {
        read(s);
    }

    // -------------------- Input / Output --------------------
    void read(const string& s) {
        sign = 1;
        a.clear();
        int pos = 0;
        while (pos < (int) s.size() && (s[pos] == '-' || s[pos] == '+')) {
            if (s[pos] == '-')
                sign = -sign;
            ++pos;
        }
        for (int i = s.size() - 1; i >= pos; i -= BASE_DIGITS) {
            int x = 0;
            for (int j = max(pos, i - BASE_DIGITS + 1); j <= i; j++)
                x = x * 10 + s[j] - '0';
            a.push_back(x);
        }
        trim();
    }
    friend istream& operator>>(istream &stream, BigInt &v) {
        string s;
        stream >> s;
        v.read(s);
        return stream;
    }

    friend ostream& operator<<(ostream &stream, const BigInt &v) {
        if (v.sign == -1 && !v.isZero())
            stream << '-';
        stream << (v.a.empty() ? 0 : v.a.back());
        for (int i = (int) v.a.size() - 2; i >= 0; --i)
            stream << setw(BASE_DIGITS) << setfill('0') << v.a[i];
        return stream;
    }

    // -------------------- Comparison --------------------
    bool operator<(const BigInt &v) const {
        if (sign != v.sign)
            return sign < v.sign;
        if (a.size() != v.a.size())
            return a.size() * sign < v.a.size() * v.sign;
        for (int i = ((int) a.size()) - 1; i >= 0; i--)
            if (a[i] != v.a[i])
                return a[i] * sign < v.a[i] * sign;
        return false;
    }

    bool operator>(const BigInt &v) const {
        return v < *this;
    }
    bool operator<=(const BigInt &v) const {
        return !(v < *this);
    }
    bool operator>=(const BigInt &v) const {
        return !(*this < v);
    }
    bool operator==(const BigInt &v) const {
        return !(*this < v) && !(v < *this);
    }
    bool operator!=(const BigInt &v) const {
        return *this < v || v < *this;
    }

    // Returns:
    // 0 if |x| == |y|
    // -1 if |x| < |y|
    // 1 if |x| > |y|
    friend int __compare_abs(const BigInt& x, const BigInt& y) {
        if (x.a.size() != y.a.size()) {
            return x.a.size() < y.a.size() ? -1 : 1;
        }

        for (int i = ((int) x.a.size()) - 1; i >= 0; --i) {
            if (x.a[i] != y.a[i]) {
                return x.a[i] < y.a[i] ? -1 : 1;
            }
        }
        return 0;
    }

    // -------------------- Unary operator - and operators +- --------------------
    BigInt operator-() const {
        BigInt res = *this;
        if (isZero()) return res;

        res.sign = -sign;
        return res;
    }

    // Note: sign ignored.
    void __internal_add(const BigInt& v) {
        if (a.size() < v.a.size()) {
            a.resize(v.a.size(), 0);
        }
        for (int i = 0, carry = 0; i < (int) max(a.size(), v.a.size()) || carry; ++i) {
            if (i == (int) a.size()) a.push_back(0);

            a[i] += carry + (i < (int) v.a.size() ? v.a[i] : 0);
            carry = a[i] >= BASE;
            if (carry) a[i] -= BASE;
        }
    }

    // Note: sign ignored.
    void __internal_sub(const BigInt& v) {
        for (int i = 0, carry = 0; i < (int) v.a.size() || carry; ++i) {
            a[i] -= carry + (i < (int) v.a.size() ? v.a[i] : 0);
            carry = a[i] < 0;
            if (carry) a[i] += BASE;
        }
        this->trim();
    }

    BigInt operator += (const BigInt& v) {
        if (sign == v.sign) {
            __internal_add(v);
        } else {
            if (__compare_abs(*this, v) >= 0) {
                __internal_sub(v);
            } else {
                BigInt vv = v;
                swap(*this, vv);
                __internal_sub(vv);
            }
        }
        return *this;
    }

    BigInt operator -= (const BigInt& v) {
        if (sign == v.sign) {
            if (__compare_abs(*this, v) >= 0) {
                __internal_sub(v);
            } else {
                BigInt vv = v;
                swap(*this, vv);
                __internal_sub(vv);
                this->sign = -this->sign;
            }
        } else {
            __internal_add(v);
        }
        return *this;
    }

    // Optimize operators + and - according to
    // https://stackoverflow.com/questions/13166079/move-semantics-and-pass-by-rvalue-reference-in-overloaded-arithmetic
    template< typename L, typename R >
        typename std::enable_if<
            std::is_convertible<L, BigInt>::value &&
            std::is_convertible<R, BigInt>::value &&
            std::is_lvalue_reference<R&&>::value,
            BigInt>::type friend operator + (L&& l, R&& r) {
        BigInt result(std::forward<L>(l));
        result += r;
        return result;
    }
    template< typename L, typename R >
        typename std::enable_if<
            std::is_convertible<L, BigInt>::value &&
            std::is_convertible<R, BigInt>::value &&
            std::is_rvalue_reference<R&&>::value,
            BigInt>::type friend operator + (L&& l, R&& r) {
        BigInt result(std::move(r));
        result += l;
        return result;
    }

    template< typename L, typename R >
        typename std::enable_if<
            std::is_convertible<L, BigInt>::value &&
            std::is_convertible<R, BigInt>::value,
            BigInt>::type friend operator - (L&& l, R&& r) {
        BigInt result(std::forward<L>(l));
        result -= r;
        return result;
    }

    // -------------------- Operators * / % --------------------
    friend pair<BigInt, BigInt> divmod(const BigInt& a1, const BigInt& b1) {
        assert(b1 > 0);  // divmod not well-defined for b < 0.

        long long norm = BASE / (b1.a.back() + 1);
        BigInt a = a1.abs() * norm;
        BigInt b = b1.abs() * norm;
        BigInt q = 0, r = 0;
        q.a.resize(a.a.size());

        for (int i = a.a.size() - 1; i >= 0; i--) {
            r *= BASE;
            r += a.a[i];
            long long s1 = r.a.size() <= b.a.size() ? 0 : r.a[b.a.size()];
            long long s2 = r.a.size() <= b.a.size() - 1 ? 0 : r.a[b.a.size() - 1];
            long long d = ((long long) BASE * s1 + s2) / b.a.back();
            r -= b * d;
            while (r < 0) {
                r += b, --d;
            }
            q.a[i] = d;
        }

        q.sign = a1.sign * b1.sign;
        r.sign = a1.sign;
        q.trim();
        r.trim();
        auto res = make_pair(q, r / norm);
        if (res.second < 0) res.second += b1;
        return res;
    }
    BigInt operator/(const BigInt &v) const {
		if(*this == 0)
			return BigInt(0);
        return divmod(*this, v).first;
    }

    BigInt operator%(const BigInt &v) const {
        return divmod(*this, v).second;
    }

    void operator/=(int v) {
        assert(v > 0);  // operator / not well-defined for v <= 0.
        if (llabs(v) >= BASE) {
            *this /= BigInt(v);
            return ;
        }
        if (v < 0)
            sign = -sign, v = -v;
        for (int i = (int) a.size() - 1, rem = 0; i >= 0; --i) {
            long long cur = a[i] + rem * (long long) BASE;
            a[i] = (int) (cur / v);
            rem = (int) (cur % v);
        }
        trim();
    }

    BigInt operator/(int v) const {
        assert(v > 0);  // operator / not well-defined for v <= 0.

        if (llabs(v) >= BASE) {
            return *this / BigInt(v);
        }
        BigInt res = *this;
        res /= v;
        return res;
    }
    void operator/=(const BigInt &v) {
        *this = *this / v;
    }

    long long operator%(long long v) const {
        assert(v > 0);  // operator / not well-defined for v <= 0.
        assert(v < BASE);
        int m = 0;
        for (int i = a.size() - 1; i >= 0; --i)
            m = (a[i] + m * (long long) BASE) % v;
        return m * sign;
    }

    void operator*=(int v) {
        if (llabs(v) >= BASE) {
            *this *= BigInt(v);
            return ;
        }
        if (v < 0)
            sign = -sign, v = -v;
        for (int i = 0, carry = 0; i < (int) a.size() || carry; ++i) {
            if (i == (int) a.size())
                a.push_back(0);
            long long cur = a[i] * (long long) v + carry;
            carry = (int) (cur / BASE);
            a[i] = (int) (cur % BASE);
            //asm("divl %%ecx" : "=a"(carry), "=d"(a[i]) : "A"(cur), "c"(base));
            /*
             int val;
             __asm {
             lea esi, cur
             mov eax, [esi]
             mov edx, [esi+4]
             mov ecx, base
             div ecx
             mov carry, eax
             mov val, edx;
             }
             a[i] = val;
             */
        }
        trim();
    }

    BigInt operator*(int v) const {
        if (llabs(v) >= BASE) {
            return *this * BigInt(v);
        }
        BigInt res = *this;
        res *= v;
        return res;
    }

    // Convert BASE 10^old --> 10^new.
    static vector<int> convert_base(const vector<int> &a, int old_digits, int new_digits) {
        vector<long long> p(max(old_digits, new_digits) + 1);
        p[0] = 1;
        for (int i = 1; i < (int) p.size(); i++)
            p[i] = p[i - 1] * 10;
        vector<int> res;
        long long cur = 0;
        int cur_digits = 0;
        for (int i = 0; i < (int) a.size(); i++) {
            cur += a[i] * p[cur_digits];
            cur_digits += old_digits;
            while (cur_digits >= new_digits) {
                res.push_back((long long)(cur % p[new_digits]));
                cur /= p[new_digits];
                cur_digits -= new_digits;
            }
        }
        res.push_back((int) cur);
        while (!res.empty() && !res.back())
            res.pop_back();
        return res;
    }

    void fft(vector<complex<double> > & a, bool invert) const {
        int n = (int) a.size();

        for (int i = 1, j = 0; i < n; ++i) {
            int bit = n >> 1;
            for (; j >= bit; bit >>= 1)
                j -= bit;
            j += bit;
            if (i < j)
                swap(a[i], a[j]);
        }

        for (int len = 2; len <= n; len <<= 1) {
            double ang = 2 * 3.14159265358979323846 / len * (invert ? -1 : 1);
            complex<double> wlen(cos(ang), sin(ang));
            for (int i = 0; i < n; i += len) {
                complex<double> w(1);
                for (int j = 0; j < len / 2; ++j) {
                    complex<double> u = a[i + j];
                    complex<double> v = a[i + j + len / 2] * w;
                    a[i + j] = u + v;
                    a[i + j + len / 2] = u - v;
                    w *= wlen;
                }
            }
        }
        if (invert)
            for (int i = 0; i < n; ++i)
                a[i] /= n;
    }

    void multiply_fft(const vector<int> &a, const vector<int> &b, vector<int> &res) const {
        vector<complex<double> > fa(a.begin(), a.end());
        vector<complex<double> > fb(b.begin(), b.end());
        int n = 1;
        while (n < (int) max(a.size(), b.size()))
            n <<= 1;
        n <<= 1;
        fa.resize(n);
        fb.resize(n);

        fft(fa, false);
        fft(fb, false);
        for (int i = 0; i < n; ++i)
            fa[i] *= fb[i];
        fft(fa, true);

        res.resize(n);
        long long carry = 0;
        for (int i = 0; i < n; ++i) {
            long long t = (long long) (fa[i].real() + 0.5) + carry;
            carry = t / 1000;
            res[i] = t % 1000;
        }
    }

    BigInt mul_simple(const BigInt &v) const {
        BigInt res;
        res.sign = sign * v.sign;
        res.a.resize(a.size() + v.a.size());
        for (int i = 0; i < (int) a.size(); ++i)
            if (a[i])
                for (int j = 0, carry = 0; j < (int) v.a.size() || carry; ++j) {
                    long long cur = res.a[i + j] + (long long) a[i] * (j < (int) v.a.size() ? v.a[j] : 0) + carry;
                    carry = (int) (cur / BASE);
                    res.a[i + j] = (int) (cur % BASE);
                }
        res.trim();
        return res;
    }

    typedef vector<long long> vll;

    static vll karatsubaMultiply(const vll &a, const vll &b) {
        int n = a.size();
        vll res(n + n);
        if (n <= 32) {
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                    res[i + j] += a[i] * b[j];
            return res;
        }

        int k = n >> 1;
        vll a1(a.begin(), a.begin() + k);
        vll a2(a.begin() + k, a.end());
        vll b1(b.begin(), b.begin() + k);
        vll b2(b.begin() + k, b.end());

        vll a1b1 = karatsubaMultiply(a1, b1);
        vll a2b2 = karatsubaMultiply(a2, b2);

        for (int i = 0; i < k; i++)
            a2[i] += a1[i];
        for (int i = 0; i < k; i++)
            b2[i] += b1[i];

        vll r = karatsubaMultiply(a2, b2);
        for (int i = 0; i < (int) a1b1.size(); i++)
            r[i] -= a1b1[i];
        for (int i = 0; i < (int) a2b2.size(); i++)
            r[i] -= a2b2[i];

        for (int i = 0; i < (int) r.size(); i++)
            res[i + k] += r[i];
        for (int i = 0; i < (int) a1b1.size(); i++)
            res[i] += a1b1[i];
        for (int i = 0; i < (int) a2b2.size(); i++)
            res[i + n] += a2b2[i];
        return res;
    }

    BigInt mul_karatsuba(const BigInt &v) const {
        vector<int> a6 = convert_base(this->a, BASE_DIGITS, 6);
        vector<int> b6 = convert_base(v.a, BASE_DIGITS, 6);
        vll a(a6.begin(), a6.end());
        vll b(b6.begin(), b6.end());
        while (a.size() < b.size())
            a.push_back(0);
        while (b.size() < a.size())
            b.push_back(0);
        while (a.size() & (a.size() - 1))
            a.push_back(0), b.push_back(0);
        vll c = karatsubaMultiply(a, b);
        BigInt res;
        res.sign = sign * v.sign;
        long long carry = 0;
        for (int i = 0; i < (int) c.size(); i++) {
            long long cur = c[i] + carry;
            res.a.push_back((int) (cur % 1000000));
            carry = cur / 1000000;
        }
        res.a = convert_base(res.a, 6, BASE_DIGITS);
        res.trim();
        return res;
    }

    void operator*=(const BigInt &v) {
        *this = *this * v;
    }
    BigInt operator*(const BigInt &v) const {
        if (a.size() * v.a.size() <= 1000111) return mul_simple(v);
        if (a.size() > 500111 || v.a.size() > 500111) return mul_fft(v);
        return mul_karatsuba(v);
    }

    BigInt mul_fft(const BigInt& v) const {
        BigInt res;
        res.sign = sign * v.sign;
        multiply_fft(convert_base(a, BASE_DIGITS, 3), convert_base(v.a, BASE_DIGITS, 3), res.a);
        res.a = convert_base(res.a, 3, BASE_DIGITS);
        res.trim();
        return res;
    }

    // -------------------- Misc --------------------
    BigInt abs() const {
        BigInt res = *this;
        res.sign *= res.sign;
        return res;
    }
    void trim() {
        while (!a.empty() && !a.back())
            a.pop_back();
        if (a.empty())
            sign = 1;
    }

    bool isZero() const {
        return a.empty() || (a.size() == 1 && !a[0]);
    }

    friend BigInt gcd(const BigInt &a, const BigInt &b) {
        return b.isZero() ? a : gcd(b, a % b);
    }
    friend BigInt lcm(const BigInt &a, const BigInt &b) {
        return a / gcd(a, b) * b;
    }

    friend BigInt sqrt(const BigInt &a1) {
        BigInt a = a1;
        while (a.a.empty() || a.a.size() % 2 == 1)
            a.a.push_back(0);

        int n = a.a.size();

        int firstDigit = (int) sqrt((double) a.a[n - 1] * BASE + a.a[n - 2]);
        int norm = BASE / (firstDigit + 1);
        a *= norm;
        a *= norm;
        while (a.a.empty() || a.a.size() % 2 == 1)
            a.a.push_back(0);

        BigInt r = (long long) a.a[n - 1] * BASE + a.a[n - 2];
        firstDigit = (int) sqrt((double) a.a[n - 1] * BASE + a.a[n - 2]);
        int q = firstDigit;
        BigInt res;

        for(int j = n / 2 - 1; j >= 0; j--) {
            for(; ; --q) {
                BigInt r1 = (r - (res * 2 * BigInt(BASE) + q) * q) * BigInt(BASE) * BigInt(BASE) + (j > 0 ? (long long) a.a[2 * j - 1] * BASE + a.a[2 * j - 2] : 0);
                if (r1 >= 0) {
                    r = r1;
                    break;
                }
            }
            res *= BASE;
            res += q;

            if (j > 0) {
                int d1 = res.a.size() + 2 < r.a.size() ? r.a[res.a.size() + 2] : 0;
                int d2 = res.a.size() + 1 < r.a.size() ? r.a[res.a.size() + 1] : 0;
                int d3 = res.a.size() < r.a.size() ? r.a[res.a.size()] : 0;
                q = ((long long) d1 * BASE * BASE + (long long) d2 * BASE + d3) / (firstDigit * 2);
            }
        }

        res.trim();
        return res / norm;
    }
};
using bi = BigInt;

/* int find_set(int a) {
    return (a == parent[a] ? a : parent[a] = find_set(parent[a]));
}
void make_set(int v) {
    parent[v] = v;
    solve[v] = 0;
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a == b) return;
    if (a != b) {
        if (solve[a] < solve[b])
            swap(a, b);
        parent[b] = a;
        solve[a]+=solve[b];
    }
} */

/* const int maxn=2e5+10;
const int len=2e5+10;
int t[4*maxn];

void build(int a[], int v, int tl, int tr) {
    if (tl == tr) {
        t[v] = a[tl];
    } else {
        int tm = (tl + tr) / 2;
        build(a, v*2, tl, tm);
        build(a, v*2+1, tm+1, tr);
        t[v] =min( t[v*2] , t[v*2+1] );
    }
}

void update(int v, int tl, int tr, int pos, int new_val) {
    if (tl == tr) {
        t[v] = new_val;
    } else {
        int tm = (tl + tr) / 2;
        if (pos <= tm)
            update(v*2, tl, tm, pos, new_val);
        else
            update(v*2+1, tm+1, tr, pos, new_val);
        t[v] = min(t[v*2] , t[v*2+1]);
    }
}

int minval(int v, int tl, int tr, int l, int r) {
    if (l > r)
        return INT_MAX;
    if (l == tl && r == tr) {
        return t[v];
    }
    int tm = (tl + tr) / 2;
    return min(minval(v*2, tl, tm, l, min(r, tm))
           , minval(v*2+1, tm+1, tr, max(l, tm+1), r));
} */

int32_t main()
{
    FAST
    cout << fixed << setprecision(6);

    string s;
    cin>>s;
    int freq[11];
    memset(freq,0,sizeof(freq));
    string f="";
    string g="";
    string my="1689";
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='1' && freq[s[i]-'0']>0)
        f+=s[i];
        else if(s[i]=='6' && freq[s[i]-'0']>0)
        f+=s[i];
        else if(s[i]=='8' && freq[s[i]-'0']>0)
        f+=s[i];
        else if(s[i]=='9' && freq[s[i]-'0']>0)
        f+=s[i];
        else if(s[i]=='0')
        g+=s[i];
        else if(s[i]!='1' && s[i]!='6' && s[i]!='8' && s[i]!='9' && s[i]!='0')
        f+=s[i];
        ++freq[s[i]-'0'];
    }
    //cout<<f<<" "<<g<<endl;
    /* int val=0;
    for(int i=0;i<f.length();i++)
    {
        val=val*10+(f[i]-'0');
    }
    cout<<val<<endl; */
    do
    {
        string dup=f+my+g;
        bi val=BigInt(dup);
        if(val%7==0)
        {
            cout<<dup<<endl;
            break;
        }
    }while(next_permutation(my.begin(),my.end()));

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define MOD3 1000000000
#define MOD2 998244353
float PHI = 1.6180339;
const float  PI_F=3.14159265358979f;
#define MAX 1000 m
#define endl "\n"
#define manhunt 32
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define PI 3.1415926535897932384626433
//typedef long long float;
#define int long long
//#define double long long
typedef pair<int, int> pii;
//#define float unsigned long long
typedef pair<int, int> pii;
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define CHAR_SIZE 26
#define pi pair<int,int>

int modpow(int x, int n, int m) { if (n == 0) return 1%m; long long u = modpow(x,n/2,m); u = (u*u)%m; if (n%2 == 1) u = (u*x)%m; return u; }

int add(int x, int y)
{
	x += y;
	if (x >= MOD2) return x - MOD2;
	return x;
}
int sub(int x, int y)
{
	x -= y;
	if (x < 0) return x + MOD2;
	return x;
}
int inv(int a, int m = MOD2)
{
	return modpow(a, m - 2, m);
}
int mul(int a, int b)
{
	return (long long) a * b % MOD2;
}

int nCrModp(int n, int r, int p)
{
    int C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;
    for (int i = 1; i <= n; i++)
    {
        for (int j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1])%p;
    }
    return C[r];
}

/* int find_set(int a) {
    return (a == parent[a] ? a : parent[a] = find_set(parent[a]));
}
void make_set(int v) {
    parent[v] = v;
    solve[v] = 0;
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a == b) return;
    if (a != b) {
        if (solve[a] < solve[b])
            swap(a, b);
        parent[b] = a;
        solve[a]+=solve[b];
    }
} */

/* const int maxn=2e5+10;
const int len=2e5+10;
int t[4*maxn];

void build(int a[], int v, int tl, int tr) {
    if (tl == tr) {
        t[v] = a[tl];
    } else {
        int tm = (tl + tr) / 2;
        build(a, v*2, tl, tm);
        build(a, v*2+1, tm+1, tr);
        t[v] =min( t[v*2] , t[v*2+1] );
    }
}

void update(int v, int tl, int tr, int pos, int new_val) {
    if (tl == tr) {
        t[v] = new_val;
    } else {
        int tm = (tl + tr) / 2;
        if (pos <= tm)
            update(v*2, tl, tm, pos, new_val);
        else
            update(v*2+1, tm+1, tr, pos, new_val);
        t[v] = min(t[v*2] , t[v*2+1]);
    }
}

int minval(int v, int tl, int tr, int l, int r) {
    if (l > r)
        return INT_MAX;
    if (l == tl && r == tr) {
        return t[v];
    }
    int tm = (tl + tr) / 2;
    return min(minval(v*2, tl, tm, l, min(r, tm))
           , minval(v*2+1, tm+1, tr, max(l, tm+1), r));
} */

int32_t main()
{
    FAST
    cout << fixed << setprecision(6);

    string s;
    cin>>s;
    int freq[11];
    memset(freq,0,sizeof(freq));
    string f="";
    string g="";
    string my="1689";
    for(int i=0;i<s.length();i++)
    {
        if(s[i]!='1' && freq[s[i]-'0']>0)
        f+=s[i];
        else if(s[i]!='6' && freq[s[i]-'0']>0)
        f+=s[i];
        else if(s[i]!='8' && freq[s[i]-'0']>0)
        f+=s[i];
        else if(s[i]!='9' && freq[s[i]-'0']>0)
        f+=s[i];
        else if(s[i]=='0')
        g+='0';
        else if(s[i]!='1' && s[i]!='6' && s[i]!='8' && s[i]!='9')
        f+=s[i];
        ++freq[s[i]-'0'];
    }

    int val=0;
    for(int i=0;i<f.length();i++)
    {
        val=val*10+(f[i]-'0');
    }
    //cout<<val<<endl;
    do
    {
        int dup=val;
        for(int i=0;i<my.length();i++)
        {
            dup=dup*10+(my[i]-'0');
        }
        if(dup%7==0)
        {
            cout<<f+my+g<<endl;
            break;
        }
    }while(next_permutation(my.begin(),my.end()));

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define MOD3 1000000000
#define MOD2 998244353
float PHI = 1.6180339;
const float  PI_F=3.14159265358979f;
#define MAX 1000 m
#define endl "\n"
#define manhunt 32
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define PI 3.1415926535897932384626433
//typedef long long float;
#define int long long
//#define double long long
typedef pair<int, int> pii;
//#define float unsigned long long
typedef pair<int, int> pii;
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define CHAR_SIZE 26
#define pi pair<int,int>

int modpow(int x, int n, int m) { if (n == 0) return 1%m; long long u = modpow(x,n/2,m); u = (u*u)%m; if (n%2 == 1) u = (u*x)%m; return u; }

int add(int x, int y)
{
	x += y;
	if (x >= MOD2) return x - MOD2;
	return x;
}
int sub(int x, int y)
{
	x -= y;
	if (x < 0) return x + MOD2;
	return x;
}
int inv(int a, int m = MOD2)
{
	return modpow(a, m - 2, m);
}
int mul(int a, int b)
{
	return (long long) a * b % MOD2;
}

int nCrModp(int n, int r, int p)
{
    int C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;
    for (int i = 1; i <= n; i++)
    {
        for (int j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1])%p;
    }
    return C[r];
}

/*
Link : https://github.com/ngthanhtrung23/ACM_Notebook_new/blob/master/Math/bigint.h
Fixed BigInt operator/ function bug where it coudn't calculate a / b if a was zero so added a condition for when a == 0;
*/
const int BASE_DIGITS = 9;
const int BASE = 1000000000;
struct BigInt {
    int sign;
    vector<int> a;

    // -------------------- Constructors --------------------
    // Default constructor.
    BigInt() : sign(1) {}

    // Constructor from long long.
    BigInt(long long v) {
        *this = v;
    }
    BigInt& operator = (long long v) {
        sign = 1;
        if (v < 0) {
            sign = -1;
            v = -v;
        }
        a.clear();
        for (; v > 0; v = v / BASE)
            a.push_back(v % BASE);
        return *this;
    }

    // Initialize from string.
    BigInt(const string& s) {
        read(s);
    }

    // -------------------- Input / Output --------------------
    void read(const string& s) {
        sign = 1;
        a.clear();
        int pos = 0;
        while (pos < (int) s.size() && (s[pos] == '-' || s[pos] == '+')) {
            if (s[pos] == '-')
                sign = -sign;
            ++pos;
        }
        for (int i = s.size() - 1; i >= pos; i -= BASE_DIGITS) {
            int x = 0;
            for (int j = max(pos, i - BASE_DIGITS + 1); j <= i; j++)
                x = x * 10 + s[j] - '0';
            a.push_back(x);
        }
        trim();
    }
    friend istream& operator>>(istream &stream, BigInt &v) {
        string s;
        stream >> s;
        v.read(s);
        return stream;
    }

    friend ostream& operator<<(ostream &stream, const BigInt &v) {
        if (v.sign == -1 && !v.isZero())
            stream << '-';
        stream << (v.a.empty() ? 0 : v.a.back());
        for (int i = (int) v.a.size() - 2; i >= 0; --i)
            stream << setw(BASE_DIGITS) << setfill('0') << v.a[i];
        return stream;
    }

    // -------------------- Comparison --------------------
    bool operator<(const BigInt &v) const {
        if (sign != v.sign)
            return sign < v.sign;
        if (a.size() != v.a.size())
            return a.size() * sign < v.a.size() * v.sign;
        for (int i = ((int) a.size()) - 1; i >= 0; i--)
            if (a[i] != v.a[i])
                return a[i] * sign < v.a[i] * sign;
        return false;
    }

    bool operator>(const BigInt &v) const {
        return v < *this;
    }
    bool operator<=(const BigInt &v) const {
        return !(v < *this);
    }
    bool operator>=(const BigInt &v) const {
        return !(*this < v);
    }
    bool operator==(const BigInt &v) const {
        return !(*this < v) && !(v < *this);
    }
    bool operator!=(const BigInt &v) const {
        return *this < v || v < *this;
    }

    // Returns:
    // 0 if |x| == |y|
    // -1 if |x| < |y|
    // 1 if |x| > |y|
    friend int __compare_abs(const BigInt& x, const BigInt& y) {
        if (x.a.size() != y.a.size()) {
            return x.a.size() < y.a.size() ? -1 : 1;
        }

        for (int i = ((int) x.a.size()) - 1; i >= 0; --i) {
            if (x.a[i] != y.a[i]) {
                return x.a[i] < y.a[i] ? -1 : 1;
            }
        }
        return 0;
    }

    // -------------------- Unary operator - and operators +- --------------------
    BigInt operator-() const {
        BigInt res = *this;
        if (isZero()) return res;

        res.sign = -sign;
        return res;
    }

    // Note: sign ignored.
    void __internal_add(const BigInt& v) {
        if (a.size() < v.a.size()) {
            a.resize(v.a.size(), 0);
        }
        for (int i = 0, carry = 0; i < (int) max(a.size(), v.a.size()) || carry; ++i) {
            if (i == (int) a.size()) a.push_back(0);

            a[i] += carry + (i < (int) v.a.size() ? v.a[i] : 0);
            carry = a[i] >= BASE;
            if (carry) a[i] -= BASE;
        }
    }

    // Note: sign ignored.
    void __internal_sub(const BigInt& v) {
        for (int i = 0, carry = 0; i < (int) v.a.size() || carry; ++i) {
            a[i] -= carry + (i < (int) v.a.size() ? v.a[i] : 0);
            carry = a[i] < 0;
            if (carry) a[i] += BASE;
        }
        this->trim();
    }

    BigInt operator += (const BigInt& v) {
        if (sign == v.sign) {
            __internal_add(v);
        } else {
            if (__compare_abs(*this, v) >= 0) {
                __internal_sub(v);
            } else {
                BigInt vv = v;
                swap(*this, vv);
                __internal_sub(vv);
            }
        }
        return *this;
    }

    BigInt operator -= (const BigInt& v) {
        if (sign == v.sign) {
            if (__compare_abs(*this, v) >= 0) {
                __internal_sub(v);
            } else {
                BigInt vv = v;
                swap(*this, vv);
                __internal_sub(vv);
                this->sign = -this->sign;
            }
        } else {
            __internal_add(v);
        }
        return *this;
    }

    // Optimize operators + and - according to
    // https://stackoverflow.com/questions/13166079/move-semantics-and-pass-by-rvalue-reference-in-overloaded-arithmetic
    template< typename L, typename R >
        typename std::enable_if<
            std::is_convertible<L, BigInt>::value &&
            std::is_convertible<R, BigInt>::value &&
            std::is_lvalue_reference<R&&>::value,
            BigInt>::type friend operator + (L&& l, R&& r) {
        BigInt result(std::forward<L>(l));
        result += r;
        return result;
    }
    template< typename L, typename R >
        typename std::enable_if<
            std::is_convertible<L, BigInt>::value &&
            std::is_convertible<R, BigInt>::value &&
            std::is_rvalue_reference<R&&>::value,
            BigInt>::type friend operator + (L&& l, R&& r) {
        BigInt result(std::move(r));
        result += l;
        return result;
    }

    template< typename L, typename R >
        typename std::enable_if<
            std::is_convertible<L, BigInt>::value &&
            std::is_convertible<R, BigInt>::value,
            BigInt>::type friend operator - (L&& l, R&& r) {
        BigInt result(std::forward<L>(l));
        result -= r;
        return result;
    }

    // -------------------- Operators * / % --------------------
    friend pair<BigInt, BigInt> divmod(const BigInt& a1, const BigInt& b1) {
        assert(b1 > 0);  // divmod not well-defined for b < 0.

        long long norm = BASE / (b1.a.back() + 1);
        BigInt a = a1.abs() * norm;
        BigInt b = b1.abs() * norm;
        BigInt q = 0, r = 0;
        q.a.resize(a.a.size());

        for (int i = a.a.size() - 1; i >= 0; i--) {
            r *= BASE;
            r += a.a[i];
            long long s1 = r.a.size() <= b.a.size() ? 0 : r.a[b.a.size()];
            long long s2 = r.a.size() <= b.a.size() - 1 ? 0 : r.a[b.a.size() - 1];
            long long d = ((long long) BASE * s1 + s2) / b.a.back();
            r -= b * d;
            while (r < 0) {
                r += b, --d;
            }
            q.a[i] = d;
        }

        q.sign = a1.sign * b1.sign;
        r.sign = a1.sign;
        q.trim();
        r.trim();
        auto res = make_pair(q, r / norm);
        if (res.second < 0) res.second += b1;
        return res;
    }
    BigInt operator/(const BigInt &v) const {
		if(*this == 0)
			return BigInt(0);
        return divmod(*this, v).first;
    }

    BigInt operator%(const BigInt &v) const {
        return divmod(*this, v).second;
    }

    void operator/=(int v) {
        assert(v > 0);  // operator / not well-defined for v <= 0.
        if (llabs(v) >= BASE) {
            *this /= BigInt(v);
            return ;
        }
        if (v < 0)
            sign = -sign, v = -v;
        for (int i = (int) a.size() - 1, rem = 0; i >= 0; --i) {
            long long cur = a[i] + rem * (long long) BASE;
            a[i] = (int) (cur / v);
            rem = (int) (cur % v);
        }
        trim();
    }

    BigInt operator/(int v) const {
        assert(v > 0);  // operator / not well-defined for v <= 0.

        if (llabs(v) >= BASE) {
            return *this / BigInt(v);
        }
        BigInt res = *this;
        res /= v;
        return res;
    }
    void operator/=(const BigInt &v) {
        *this = *this / v;
    }

    long long operator%(long long v) const {
        assert(v > 0);  // operator / not well-defined for v <= 0.
        assert(v < BASE);
        int m = 0;
        for (int i = a.size() - 1; i >= 0; --i)
            m = (a[i] + m * (long long) BASE) % v;
        return m * sign;
    }

    void operator*=(int v) {
        if (llabs(v) >= BASE) {
            *this *= BigInt(v);
            return ;
        }
        if (v < 0)
            sign = -sign, v = -v;
        for (int i = 0, carry = 0; i < (int) a.size() || carry; ++i) {
            if (i == (int) a.size())
                a.push_back(0);
            long long cur = a[i] * (long long) v + carry;
            carry = (int) (cur / BASE);
            a[i] = (int) (cur % BASE);
            //asm("divl %%ecx" : "=a"(carry), "=d"(a[i]) : "A"(cur), "c"(base));
            /*
             int val;
             __asm {
             lea esi, cur
             mov eax, [esi]
             mov edx, [esi+4]
             mov ecx, base
             div ecx
             mov carry, eax
             mov val, edx;
             }
             a[i] = val;
             */
        }
        trim();
    }

    BigInt operator*(int v) const {
        if (llabs(v) >= BASE) {
            return *this * BigInt(v);
        }
        BigInt res = *this;
        res *= v;
        return res;
    }

    // Convert BASE 10^old --> 10^new.
    static vector<int> convert_base(const vector<int> &a, int old_digits, int new_digits) {
        vector<long long> p(max(old_digits, new_digits) + 1);
        p[0] = 1;
        for (int i = 1; i < (int) p.size(); i++)
            p[i] = p[i - 1] * 10;
        vector<int> res;
        long long cur = 0;
        int cur_digits = 0;
        for (int i = 0; i < (int) a.size(); i++) {
            cur += a[i] * p[cur_digits];
            cur_digits += old_digits;
            while (cur_digits >= new_digits) {
                res.push_back((long long)(cur % p[new_digits]));
                cur /= p[new_digits];
                cur_digits -= new_digits;
            }
        }
        res.push_back((int) cur);
        while (!res.empty() && !res.back())
            res.pop_back();
        return res;
    }

    void fft(vector<complex<double> > & a, bool invert) const {
        int n = (int) a.size();

        for (int i = 1, j = 0; i < n; ++i) {
            int bit = n >> 1;
            for (; j >= bit; bit >>= 1)
                j -= bit;
            j += bit;
            if (i < j)
                swap(a[i], a[j]);
        }

        for (int len = 2; len <= n; len <<= 1) {
            double ang = 2 * 3.14159265358979323846 / len * (invert ? -1 : 1);
            complex<double> wlen(cos(ang), sin(ang));
            for (int i = 0; i < n; i += len) {
                complex<double> w(1);
                for (int j = 0; j < len / 2; ++j) {
                    complex<double> u = a[i + j];
                    complex<double> v = a[i + j + len / 2] * w;
                    a[i + j] = u + v;
                    a[i + j + len / 2] = u - v;
                    w *= wlen;
                }
            }
        }
        if (invert)
            for (int i = 0; i < n; ++i)
                a[i] /= n;
    }

    void multiply_fft(const vector<int> &a, const vector<int> &b, vector<int> &res) const {
        vector<complex<double> > fa(a.begin(), a.end());
        vector<complex<double> > fb(b.begin(), b.end());
        int n = 1;
        while (n < (int) max(a.size(), b.size()))
            n <<= 1;
        n <<= 1;
        fa.resize(n);
        fb.resize(n);

        fft(fa, false);
        fft(fb, false);
        for (int i = 0; i < n; ++i)
            fa[i] *= fb[i];
        fft(fa, true);

        res.resize(n);
        long long carry = 0;
        for (int i = 0; i < n; ++i) {
            long long t = (long long) (fa[i].real() + 0.5) + carry;
            carry = t / 1000;
            res[i] = t % 1000;
        }
    }

    BigInt mul_simple(const BigInt &v) const {
        BigInt res;
        res.sign = sign * v.sign;
        res.a.resize(a.size() + v.a.size());
        for (int i = 0; i < (int) a.size(); ++i)
            if (a[i])
                for (int j = 0, carry = 0; j < (int) v.a.size() || carry; ++j) {
                    long long cur = res.a[i + j] + (long long) a[i] * (j < (int) v.a.size() ? v.a[j] : 0) + carry;
                    carry = (int) (cur / BASE);
                    res.a[i + j] = (int) (cur % BASE);
                }
        res.trim();
        return res;
    }

    typedef vector<long long> vll;

    static vll karatsubaMultiply(const vll &a, const vll &b) {
        int n = a.size();
        vll res(n + n);
        if (n <= 32) {
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                    res[i + j] += a[i] * b[j];
            return res;
        }

        int k = n >> 1;
        vll a1(a.begin(), a.begin() + k);
        vll a2(a.begin() + k, a.end());
        vll b1(b.begin(), b.begin() + k);
        vll b2(b.begin() + k, b.end());

        vll a1b1 = karatsubaMultiply(a1, b1);
        vll a2b2 = karatsubaMultiply(a2, b2);

        for (int i = 0; i < k; i++)
            a2[i] += a1[i];
        for (int i = 0; i < k; i++)
            b2[i] += b1[i];

        vll r = karatsubaMultiply(a2, b2);
        for (int i = 0; i < (int) a1b1.size(); i++)
            r[i] -= a1b1[i];
        for (int i = 0; i < (int) a2b2.size(); i++)
            r[i] -= a2b2[i];

        for (int i = 0; i < (int) r.size(); i++)
            res[i + k] += r[i];
        for (int i = 0; i < (int) a1b1.size(); i++)
            res[i] += a1b1[i];
        for (int i = 0; i < (int) a2b2.size(); i++)
            res[i + n] += a2b2[i];
        return res;
    }

    BigInt mul_karatsuba(const BigInt &v) const {
        vector<int> a6 = convert_base(this->a, BASE_DIGITS, 6);
        vector<int> b6 = convert_base(v.a, BASE_DIGITS, 6);
        vll a(a6.begin(), a6.end());
        vll b(b6.begin(), b6.end());
        while (a.size() < b.size())
            a.push_back(0);
        while (b.size() < a.size())
            b.push_back(0);
        while (a.size() & (a.size() - 1))
            a.push_back(0), b.push_back(0);
        vll c = karatsubaMultiply(a, b);
        BigInt res;
        res.sign = sign * v.sign;
        long long carry = 0;
        for (int i = 0; i < (int) c.size(); i++) {
            long long cur = c[i] + carry;
            res.a.push_back((int) (cur % 1000000));
            carry = cur / 1000000;
        }
        res.a = convert_base(res.a, 6, BASE_DIGITS);
        res.trim();
        return res;
    }

    void operator*=(const BigInt &v) {
        *this = *this * v;
    }
    BigInt operator*(const BigInt &v) const {
        if (a.size() * v.a.size() <= 1000111) return mul_simple(v);
        if (a.size() > 500111 || v.a.size() > 500111) return mul_fft(v);
        return mul_karatsuba(v);
    }

    BigInt mul_fft(const BigInt& v) const {
        BigInt res;
        res.sign = sign * v.sign;
        multiply_fft(convert_base(a, BASE_DIGITS, 3), convert_base(v.a, BASE_DIGITS, 3), res.a);
        res.a = convert_base(res.a, 3, BASE_DIGITS);
        res.trim();
        return res;
    }

    // -------------------- Misc --------------------
    BigInt abs() const {
        BigInt res = *this;
        res.sign *= res.sign;
        return res;
    }
    void trim() {
        while (!a.empty() && !a.back())
            a.pop_back();
        if (a.empty())
            sign = 1;
    }

    bool isZero() const {
        return a.empty() || (a.size() == 1 && !a[0]);
    }

    friend BigInt gcd(const BigInt &a, const BigInt &b) {
        return b.isZero() ? a : gcd(b, a % b);
    }
    friend BigInt lcm(const BigInt &a, const BigInt &b) {
        return a / gcd(a, b) * b;
    }

    friend BigInt sqrt(const BigInt &a1) {
        BigInt a = a1;
        while (a.a.empty() || a.a.size() % 2 == 1)
            a.a.push_back(0);

        int n = a.a.size();

        int firstDigit = (int) sqrt((double) a.a[n - 1] * BASE + a.a[n - 2]);
        int norm = BASE / (firstDigit + 1);
        a *= norm;
        a *= norm;
        while (a.a.empty() || a.a.size() % 2 == 1)
            a.a.push_back(0);

        BigInt r = (long long) a.a[n - 1] * BASE + a.a[n - 2];
        firstDigit = (int) sqrt((double) a.a[n - 1] * BASE + a.a[n - 2]);
        int q = firstDigit;
        BigInt res;

        for(int j = n / 2 - 1; j >= 0; j--) {
            for(; ; --q) {
                BigInt r1 = (r - (res * 2 * BigInt(BASE) + q) * q) * BigInt(BASE) * BigInt(BASE) + (j > 0 ? (long long) a.a[2 * j - 1] * BASE + a.a[2 * j - 2] : 0);
                if (r1 >= 0) {
                    r = r1;
                    break;
                }
            }
            res *= BASE;
            res += q;

            if (j > 0) {
                int d1 = res.a.size() + 2 < r.a.size() ? r.a[res.a.size() + 2] : 0;
                int d2 = res.a.size() + 1 < r.a.size() ? r.a[res.a.size() + 1] : 0;
                int d3 = res.a.size() < r.a.size() ? r.a[res.a.size()] : 0;
                q = ((long long) d1 * BASE * BASE + (long long) d2 * BASE + d3) / (firstDigit * 2);
            }
        }

        res.trim();
        return res / norm;
    }
};
using bi = BigInt;

/* int find_set(int a) {
    return (a == parent[a] ? a : parent[a] = find_set(parent[a]));
}
void make_set(int v) {
    parent[v] = v;
    solve[v] = 0;
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a == b) return;
    if (a != b) {
        if (solve[a] < solve[b])
            swap(a, b);
        parent[b] = a;
        solve[a]+=solve[b];
    }
} */

/* const int maxn=2e5+10;
const int len=2e5+10;
int t[4*maxn];

void build(int a[], int v, int tl, int tr) {
    if (tl == tr) {
        t[v] = a[tl];
    } else {
        int tm = (tl + tr) / 2;
        build(a, v*2, tl, tm);
        build(a, v*2+1, tm+1, tr);
        t[v] =min( t[v*2] , t[v*2+1] );
    }
}

void update(int v, int tl, int tr, int pos, int new_val) {
    if (tl == tr) {
        t[v] = new_val;
    } else {
        int tm = (tl + tr) / 2;
        if (pos <= tm)
            update(v*2, tl, tm, pos, new_val);
        else
            update(v*2+1, tm+1, tr, pos, new_val);
        t[v] = min(t[v*2] , t[v*2+1]);
    }
}

int minval(int v, int tl, int tr, int l, int r) {
    if (l > r)
        return INT_MAX;
    if (l == tl && r == tr) {
        return t[v];
    }
    int tm = (tl + tr) / 2;
    return min(minval(v*2, tl, tm, l, min(r, tm))
           , minval(v*2+1, tm+1, tr, max(l, tm+1), r));
} */

int32_t main()
{
    FAST
    cout << fixed << setprecision(6);

    string s;
    cin>>s;
    int freq[11];
    memset(freq,0,sizeof(freq));
    string f="";
    string g="";
    string my="1689";
    for(int i=0;i<s.length();i++)
    {
        if(s[i]!='1' && freq[s[i]-'0']>0)
        f+=s[i];
        else if(s[i]!='6' && freq[s[i]-'0']>0)
        f+=s[i];
        else if(s[i]!='8' && freq[s[i]-'0']>0)
        f+=s[i];
        else if(s[i]!='9' && freq[s[i]-'0']>0)
        f+=s[i];
        else if(s[i]=='0')
        g+='0';
        else if(s[i]!='1' && s[i]!='6' && s[i]!='8' && s[i]!='9')
        f+=s[i];
        ++freq[s[i]-'0'];
    }

    /* int val=0;
    for(int i=0;i<f.length();i++)
    {
        val=val*10+(f[i]-'0');
    }
    cout<<val<<endl; */
    do
    {
        string dup=f+my+g;
        bi val=BigInt(dup);
        if(val%7==0)
        {
            cout<<dup<<endl;
            break;
        }
    }while(next_permutation(my.begin(),my.end()));

    return 0;
}


// @tushaar11
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pf push_front
#define mp make_pair
#define pii pair<int,int>
#define pid pair<int,double>
#define vi vector<int>
#define ff first
#define ss second
#define int long long int
#define ull unsigned long long
#define PI 3.14159265
#define SIZE 200010
#define MOD 1000000007
#define BIG 998244353
#define s(t) scanf("%d",&t)
#define p(t) printf("%d\n",t)
#define mii map<int,int>
#define tc int tcs;cin>>tcs;while(tcs--)
#define set_bit __builtin_popcount
#define MSET(table,i) memset(table, i, sizeof(table))
int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ){stringstream ss; ss<< number; return ss.str();}
int maxarr(int arr[],int n)
{
    int maxval=INT_MIN;
    for(int i=0;i<n;i++)
    {
        maxval=max(maxval,arr[i]);
    }
    return maxval;
}
int minarr(int arr[],int n)
{
    int minval=INT_MAX;
    for(int i=0;i<n;i++)
    {
        minval=min(minval,arr[i]);
    }
    return minval;
}
bool comp(pair<int,int > p1, pair<int ,int > p2)
{
    if(abs(p1.first)  < abs( p2.first)  )
    {
        return true;
    }
    else if(abs(p1.first)  > abs( p2.first))
    {
        return false;
    }
    else
    {
        if(abs(p1.second)<abs(p2.second))
        return true;
        else
        return false;
    }

}
int count(int n)
{
    int cnt=0;
    while(n)
    {
        cnt++;
        n=n/10;
    }
    return cnt;
}
vector<int> seive(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {

        if (prime[p] == true)
        {

            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    vector<int> v;
    for (int p=2; p<=n; p++)
       if (prime[p])
          v.pb(p);

    return v;
}
int k;
bool f(int sz,int&val,int presum[],int arr[],int n)
{

    for(int i=sz;i<=n;i++)
    {
        if( sz*arr[i] - (presum[i]-presum[i-sz]) <= k )
        {
            val=arr[i];

            return true;
        }
    }
    return false;
}
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
double angle(int x,int y)
{
    if(y==0 )
    {
     if(x<0)
     {
         return 180;
     }
     else
     {
         return 0;
     }
    }
    if(x==0 && y>0)
    {
        return 90.0;
    }
    else if(x==0 && y<0)
    {
        return 270.0;
    }

    // double k = );
    // double ret =

    double val = (atan((abs(y)*1.0)/abs(x)) * 180.0) / PI;

    if(y>0 && x<0)
    {
        val = 180 - val;
    }
    else if(y<0 && x<0)
    {
        val = 180 + val;
    }
    else if(y<0 && x>0)
    {
        val = 360 - val;
    }

    return val;
}

int32_t main()
{
    fast;

    string s;
    cin>>s;
    int arr[10]={0};
    for(int i=0;i<s.length();i++)
    {
        arr[s[i] - '0']++;
    }
    int rem[7];
    rem[0]=1869;
    rem[6]=1896;
    rem[5]=1986;
    rem[1]=1968;
    rem[2]=1689;
    rem[4]=1698;
    rem[3]=6891;

    arr[1]--;
    arr[6]--;
    arr[8]--;
    arr[9]--;

    int re =0;
    for(int i=1;i<10;i++)
    {
        for(int k=1;k<=arr[i];k++)
        {
            re = (re*10 + i )%7;
            cout<<i;
        }
    }

    re= ( re * (10000)%7 )%7;

    cout<<rem[7-re];

    for(int i=1;i<=arr[0];i++)
    cout<<0;
    return 0;
}


// @tushaar11
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pf push_front
#define mp make_pair
#define pii pair<int,int>
#define pid pair<int,double>
#define vi vector<int>
#define ff first
#define ss second
#define int long long int
#define ull unsigned long long
#define PI 3.14159265
#define SIZE 200010
#define MOD 1000000007
#define BIG 998244353
#define s(t) scanf("%d",&t)
#define p(t) printf("%d\n",t)
#define mii map<int,int>
#define tc int tcs;cin>>tcs;while(tcs--)
#define set_bit __builtin_popcount
#define MSET(table,i) memset(table, i, sizeof(table))
int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ){stringstream ss; ss<< number; return ss.str();}
int maxarr(int arr[],int n)
{
    int maxval=INT_MIN;
    for(int i=0;i<n;i++)
    {
        maxval=max(maxval,arr[i]);
    }
    return maxval;
}
int minarr(int arr[],int n)
{
    int minval=INT_MAX;
    for(int i=0;i<n;i++)
    {
        minval=min(minval,arr[i]);
    }
    return minval;
}
bool comp(pair<int,int > p1, pair<int ,int > p2)
{
    if(abs(p1.first)  < abs( p2.first)  )
    {
        return true;
    }
    else if(abs(p1.first)  > abs( p2.first))
    {
        return false;
    }
    else
    {
        if(abs(p1.second)<abs(p2.second))
        return true;
        else
        return false;
    }

}
int count(int n)
{
    int cnt=0;
    while(n)
    {
        cnt++;
        n=n/10;
    }
    return cnt;
}
vector<int> seive(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {

        if (prime[p] == true)
        {

            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    vector<int> v;
    for (int p=2; p<=n; p++)
       if (prime[p])
          v.pb(p);

    return v;
}
int k;
bool f(int sz,int&val,int presum[],int arr[],int n)
{

    for(int i=sz;i<=n;i++)
    {
        if( sz*arr[i] - (presum[i]-presum[i-sz]) <= k )
        {
            val=arr[i];

            return true;
        }
    }
    return false;
}
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
double angle(int x,int y)
{
    if(y==0 )
    {
     if(x<0)
     {
         return 180;
     }
     else
     {
         return 0;
     }
    }
    if(x==0 && y>0)
    {
        return 90.0;
    }
    else if(x==0 && y<0)
    {
        return 270.0;
    }

    // double k = );
    // double ret =

    double val = (atan((abs(y)*1.0)/abs(x)) * 180.0) / PI;

    if(y>0 && x<0)
    {
        val = 180 - val;
    }
    else if(y<0 && x<0)
    {
        val = 180 + val;
    }
    else if(y<0 && x>0)
    {
        val = 360 - val;
    }

    return val;
}

int32_t main()
{
    fast;

    string s;
    cin>>s;
    int arr[10]={0};
    for(int i=0;i<s.length();i++)
    {
        arr[s[i] - '0']++;
    }
    int rem[7];
    rem[0]=1869;
    rem[6]=1896;
    rem[5]=1986;
    rem[1]=1968;
    rem[2]=1689;
    rem[4]=1698;
    rem[3]=6891;

    arr[1]--;
    arr[6]--;
    arr[8]--;
    arr[9]--;

    int re =0;
    for(int i=1;i<10;i++)
    {
        for(int k=1;k<=arr[i];k++)
        {
            re = (re*10 + i )%7;
            cout<<i;
        }
    }

    re= ( re * (10000)%7 )%7;
    if(re==0)
    cout<<rem[0];
    else
    cout<<rem[7-re];
    // switch(re)
    // {
    //     case 0:
    //     {
    //         cout<<rem[0];
    //         break;
    //     }
    //     case 1:
    //     {
    //         cout<<rem[4];
    //         break;
    //     }
    //     case 2:
    //     {
    //         cout<<rem[1];
    //         break;
    //     }
    //     case 3:
    //     {
    //         cout<<rem[5];
    //         break;
    //     }
    //     case 4:
    //     {
    //         cout<<rem[2];
    //         break;
    //     }
    //     case 5:
    //     {
    //         cout<<rem[6];
    //         break;
    //     }
    //     case 6:
    //     {
    //         cout<<rem[3];
    //         break;
    //     }
    // }
    for(int i=1;i<=arr[0];i++)
    cout<<0;
    return 0;
}


// @tushaar11
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pf push_front
#define mp make_pair
#define pii pair<int,int>
#define pid pair<int,double>
#define vi vector<int>
#define ff first
#define ss second
#define int long long int
#define ull unsigned long long
#define PI 3.14159265
#define SIZE 200010
#define MOD 1000000007
#define BIG 998244353
#define s(t) scanf("%d",&t)
#define p(t) printf("%d\n",t)
#define mii map<int,int>
#define tc int tcs;cin>>tcs;while(tcs--)
#define set_bit __builtin_popcount
#define MSET(table,i) memset(table, i, sizeof(table))
int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ){stringstream ss; ss<< number; return ss.str();}
int maxarr(int arr[],int n)
{
    int maxval=INT_MIN;
    for(int i=0;i<n;i++)
    {
        maxval=max(maxval,arr[i]);
    }
    return maxval;
}
int minarr(int arr[],int n)
{
    int minval=INT_MAX;
    for(int i=0;i<n;i++)
    {
        minval=min(minval,arr[i]);
    }
    return minval;
}
bool comp(pair<int,int > p1, pair<int ,int > p2)
{
    if(abs(p1.first)  < abs( p2.first)  )
    {
        return true;
    }
    else if(abs(p1.first)  > abs( p2.first))
    {
        return false;
    }
    else
    {
        if(abs(p1.second)<abs(p2.second))
        return true;
        else
        return false;
    }

}
int count(int n)
{
    int cnt=0;
    while(n)
    {
        cnt++;
        n=n/10;
    }
    return cnt;
}
vector<int> seive(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {

        if (prime[p] == true)
        {

            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    vector<int> v;
    for (int p=2; p<=n; p++)
       if (prime[p])
          v.pb(p);

    return v;
}
int k;
bool f(int sz,int&val,int presum[],int arr[],int n)
{

    for(int i=sz;i<=n;i++)
    {
        if( sz*arr[i] - (presum[i]-presum[i-sz]) <= k )
        {
            val=arr[i];

            return true;
        }
    }
    return false;
}
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
double angle(int x,int y)
{
    if(y==0 )
    {
     if(x<0)
     {
         return 180;
     }
     else
     {
         return 0;
     }
    }
    if(x==0 && y>0)
    {
        return 90.0;
    }
    else if(x==0 && y<0)
    {
        return 270.0;
    }

    // double k = );
    // double ret =

    double val = (atan((abs(y)*1.0)/abs(x)) * 180.0) / PI;

    if(y>0 && x<0)
    {
        val = 180 - val;
    }
    else if(y<0 && x<0)
    {
        val = 180 + val;
    }
    else if(y<0 && x>0)
    {
        val = 360 - val;
    }

    return val;
}

int32_t main()
{
    fast;

    string s;
    cin>>s;
    int arr[10]={0};
    for(int i=0;i<s.length();i++)
    {
        arr[s[i] - '0']++;
    }
    int rem[7];
    rem[0]=1869;
    rem[6]=1896;
    rem[5]=1986;
    rem[1]=1968;
    rem[2]=1689;
    rem[4]=1698;
    rem[3]=6891;

    arr[1]--;
    arr[6]--;
    arr[8]--;
    arr[9]--;

    int re =0;
    for(int i=1;i<10;i++)
    {
        for(int k=1;k<=arr[i];k++)
        {
            re = (re*10 + i )%7;
            cout<<i;
        }
    }

    switch(re)
    {
        case 0:
        {
            cout<<rem[0];
            break;
        }
        case 1:
        {
            cout<<rem[4];
            break;
        }
        case 2:
        {
            cout<<rem[1];
            break;
        }
        case 3:
        {
            cout<<rem[5];
            break;
        }
        case 4:
        {
            cout<<rem[2];
            break;
        }
        case 5:
        {
            cout<<rem[6];
            break;
        }
        case 6:
        {
            cout<<rem[3];
            break;
        }
    }
    for(int i=1;i<=arr[0];i++)
    cout<<0;
    return 0;
}


/*
 _____ _             _              _           _
|_   _| |__   ___   / \   _ __  ___| |__  _   _| |
  | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  | | | | | |  __// ___ \| | | \__ \ | | | |_| | |
  |_| |_| |_|\___/_/   \_\_| |_|___/_| |_|\__,_|_|

*/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vii         vector<pair<ll int, ll int>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
#define N  1000005
ll pw[N];
void solve()
{
	ll ans[]={1869,1896,1986,1698,6198,1689,1968};
	ll n;
	string s;
	cin>>s;
	n=s.length();
	pw[0]=1;
	rep(i,1,n+1)
	{
		pw[i]=(pw[i-1]*10)%7;
	}
	map<ll,ll>mp;
	rep(i,0,n)
	mp[(s[i]-'0')]++;
	ll ps=n-1,ts=0;
	for(auto i:mp)
	{
		if(i.F==0)
			continue;
		ll p=0;
		if(i.F==1 || i.F==6 || i.F==8 || i.F==9)
			p=1;
		rep(j,p,i.S)
		{
			cout<<i.F;
			ts=(ts+pw[ps]*i.F)%7;
			ps--;
		}
	}
	// cerr<<ps<<endl;
	cout<<ans[(ts*pw[ps-4])%7];
	rep(i,0,mp[0])
	cout<<0;
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	time
	return 0;
}


/*
 _____ _             _              _           _
|_   _| |__   ___   / \   _ __  ___| |__  _   _| |
  | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  | | | | | |  __// ___ \| | | \__ \ | | | |_| | |
  |_| |_| |_|\___/_/   \_\_| |_|___/_| |_|\__,_|_|

*/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vii         vector<pair<ll int, ll int>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
#define N  1000005
ll pw[N];
void solve()
{
	ll ans[]={1869,1896,1986,1698,6198,1689,1968};
	ll n;
	string s;
	cin>>s;
	n=s.length();
	pw[0]=1;
	rep(i,1,n+1)
	{
		pw[i]=(pw[i-1]*10)%7;
	}
	map<ll,ll>mp;
	rep(i,0,n)
	mp[(s[i]-'0')]++;
	ll ps=n-1,ts=0;
	for(auto i:mp)
	{
		if(i.F==0)
			continue;
		ll p=0;
		if(i.F==1 || i.F==6 || i.F==8 || i.F==9)
			p=1;
		rep(j,p,i.S)
		{
			cout<<i.F;
			ts=(ts+pw[ps]*i.F)%7;
			ps--;
		}
	}
	rep(i,0,mp[0])
	cout<<0;
	cout<<ans[ts%7];
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	time
	return 0;
}


/*
 _____ _             _              _           _
|_   _| |__   ___   / \   _ __  ___| |__  _   _| |
  | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  | | | | | |  __// ___ \| | | \__ \ | | | |_| | |
  |_| |_| |_|\___/_/   \_\_| |_|___/_| |_|\__,_|_|

*/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vii         vector<pair<ll int, ll int>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
#define N  1000005
ll pw[N];
void solve()
{
	ll ans[]={1869,1896,1986,1698,6198,1689,1968};
	ll n;
	string s;
	cin>>s;
	n=s.length();
	pw[0]=1;
	rep(i,1,n+1)
	{
		pw[i]=(pw[i-1]*10)%7;
	}
	map<ll,ll>mp;
	rep(i,0,n)
	mp[(s[i]-'0')]++;
	ll ps=n-1,ts=0;
	for(auto i:mp)
	{
		if(i.F==0)
			continue;
		ll p=0;
		if(i.F==1 || i.F==6 || i.F==8 || i.F==9)
			p=1;
		rep(j,p,i.S)
		{
			cout<<i.F;
			ts=(ts+pw[ps]*i.F)%7;
			ps--;
		}
	}
	// cerr<<ps<<endl;
	cout<<ans[(ts*pw[ps-3])%7];
	rep(i,0,mp[0])
	cout<<0;
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	time
	return 0;
}


/*
 _____ _             _              _           _
|_   _| |__   ___   / \   _ __  ___| |__  _   _| |
  | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  | | | | | |  __// ___ \| | | \__ \ | | | |_| | |
  |_| |_| |_|\___/_/   \_\_| |_|___/_| |_|\__,_|_|

*/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vii         vector<pair<ll int, ll int>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
#define N  1000005
ll pw[N];
void solve()
{
	ll ans[]={1869,1896,1986,1698,6198,1689,1968};
	ll n;
	string s;
	cin>>s;
	n=s.length();
	pw[0]=1;
	rep(i,1,n+1)
	{
		pw[i]=(pw[i-1]*10)%7;
	}
	map<ll,ll>mp;
	rep(i,0,n)
	mp[(s[i]-'0')]++;
	ll ps=n-1,ts=0;
	for(auto i:mp)
	{
		if(i.F==0)
			continue;
		ll p=0;
		if(i.F==1 || i.F==6 || i.F==8 || i.F==9)
			p=1;
		rep(j,p,i.S)
		{
			cout<<i.F;
			ts=(ts+pw[ps]*i.F)%7;
			ps--;
		}
	}
	cout<<ans[ts%7];
	rep(i,0,mp[0])
	cout<<0;
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	time
	return 0;
}


/*
 _____ _             _              _           _
|_   _| |__   ___   / \   _ __  ___| |__  _   _| |
  | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  | | | | | |  __// ___ \| | | \__ \ | | | |_| | |
  |_| |_| |_|\___/_/   \_\_| |_|___/_| |_|\__,_|_|

*/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vii         vector<pair<ll int, ll int>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
#define N  1000005
ll pw[N];
ll expo(ll base, ll exponent, ll mod) {								//return base^exponent modulo modulus
    ll ans = 1;
    while(exponent !=0 ) {
        if((exponent&1) == 1) {
            ans = ans*base ;
            ans = ans%mod;
        }
        base = base*base;
        base %= mod;
        exponent>>= 1;
    }
    return ans%mod;
}
void solve()
{
	ll ans[]={1869,1896,1986,1698,6198,1689,1968};
	ll n;
	string s;
	cin>>s;
	n=s.length();
	pw[0]=1;
	rep(i,1,n+1)
	{
		pw[i]=(pw[i-1]*10)%7;
	}
	map<ll,ll>mp;
	rep(i,0,n)
	mp[(s[i]-'0')]++;
	vi pst;
	ll ps=n-1,ts=0;
	for(auto i:mp)
	{
		if(i.F==0)
			continue;
		ll p=0;
		if(i.F==1 || i.F==6 || i.F==8 || i.F==9)
			p=1;
		rep(j,p,i.S)
		{
			cout<<i.F;
			// pst.pb(i.F);
			ts=(ts+pw[ps]*i.F)%7;
			ps--;
		}
	}
	// cerr<<ps<<endl;
	cout<<ans[(7-((7-ts)*expo(pw[ps-3],5,7))%7)%7];
	rep(i,0,mp[0])
	cout<<0;
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	time
	return 0;
}


/*
 _____ _             _              _           _
|_   _| |__   ___   / \   _ __  ___| |__  _   _| |
  | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  | | | | | |  __// ___ \| | | \__ \ | | | |_| | |
  |_| |_| |_|\___/_/   \_\_| |_|___/_| |_|\__,_|_|

*/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vii         vector<pair<ll int, ll int>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
#define N  1000005
ll pw[N];
void solve()
{
	ll ans[]={1869,1896,1986,1698,6198,1689,1968};
	ll n;
	string s;
	cin>>s;
	n=s.length();
	pw[0]=1;
	rep(i,1,n+1)
	{
		pw[i]=(pw[i-1]*10)%7;
	}
	map<ll,ll>mp;
	rep(i,0,n)
	mp[(s[i]-'0')]++;
	ll ps=n-1,ts=0;
	for(auto i:mp)
	{
		if(i.F==0)
			continue;
		rep(j,1,i.S)
		{
			cout<<i.F;
			ts=(ts+pw[ps]*i.F)%7;
			ps--;
		}
	}
	cout<<ans[ts%7];
	rep(i,0,mp[0])
	cout<<0;
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	time
	return 0;
}


/*
 _____ _             _              _           _
|_   _| |__   ___   / \   _ __  ___| |__  _   _| |
  | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  | | | | | |  __// ___ \| | | \__ \ | | | |_| | |
  |_| |_| |_|\___/_/   \_\_| |_|___/_| |_|\__,_|_|

*/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vii         vector<pair<ll int, ll int>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
#define N  1000005
ll pw[N];
ll expo(ll base, ll exponent, ll mod) {								//return base^exponent modulo modulus
    ll ans = 1;
    while(exponent !=0 ) {
        if((exponent&1) == 1) {
            ans = ans*base ;
            ans = ans%mod;
        }
        base = base*base;
        base %= mod;
        exponent>>= 1;
    }
    return ans%mod;
}
void solve()
{
	ll ans[]={1869,1896,1986,1698,6198,1689,1968};
	ll n;
	string s;
	cin>>s;
	n=s.length();
	pw[0]=1;
	rep(i,1,n+1)
	{
		pw[i]=(pw[i-1]*10)%7;
	}
	map<ll,ll>mp;
	rep(i,0,n)
	mp[(s[i]-'0')]++;
	vi pst;
	ll ps=n-1,ts=0;
	for(auto i:mp)
	{
		if(i.F==0)
			continue;
		ll p=0;
		if(i.F==1 || i.F==6 || i.F==8 || i.F==9)
			p=1;
		rep(j,p,i.S)
		{
			// cout<<i.F;
			pst.pb(i.F);
			ts=(ts+pw[ps]*i.F)%7;
			ps--;
		}
	}
	// cerr<<ps<<endl;
	cout<<ans[(7-((7-ts)*expo(pw[ps-3],5,7))%7)%7];
	rep(i,0,mp[0])
	cout<<0;
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	time
	return 0;
}