/*
TASK:money
LANG:C++
*/
#include<iostream.h>
#include<string.h>
#include<stdio.h>
//using namespace std;
char mah[80],chek1[80],rez[1];
int main()
{
int a=0,j,x,y,k;
long chek=0;
char s[80];
for(;;){
	gets(s);
	for(j=0;j<=strlen(s);j++){
		if(s[j]=='#'){
			      a=1;break;
			      }
		if(s[j]-'0'<=9&&s[j]-'0'>=0){
							     chek+=s[j]-'0';
							     rez[0]=s[j];
							     strcat(chek1,rez);
							     }
		}
	x=strlen(mah);
	y=strlen(chek1);
	if(chek%3==0&&x<=y){
			    if(x<y)strcpy(mah, chek1);
			    else for(k=0;k<=x;k++){
				 if(mah[k]==chek1[k])continue;
				 if(mah[k]>chek1[k])break;
				 if(mah[k]<chek1[k]){
						strcpy(mah, chek1);break;
						}
				 }
			    }
	if(a==1)break;
}
if(strlen(mah)>0)cout<<mah<<"\n";
else cout<<"NO\n";
//system("PAUSE");
return 0;
}
