#include <stdio.h>
int main(){
	int a=0;
	int base=0;
	int n=1;
	char c;
	while(base<2 || base>(10+'z'-'a')){
		printf("Inserire la base: ");
		scanf("%d", &base);
	}
	
	while(c!='*'){
		do 
			scanf("%c",&c);
		while((c<'a'|| c>'z')&&(c<'0' || c>'9')&&(c!='*'));
		int cifra;
        if (c!='*'){
		    if (c>='a' && c<='z') cifra=c-'a'+10;
		    else cifra=c-'0';
		    a = a + cifra*n;
		    n=n*base;
        }    
	}
	printf("a=%d\n",a);
	return 0;
}
