/*
 * ????.cpp
 * ???????????????????2???36???
 * ????: 2010-11-9
 * ??: ??
 */

//?????


//???
int main() {

	//??a, n, b???????
	char n[101];
	int a, b, length, i, j, temp; //length????????temp???
	long int value = 0, product; //value???????product??????
	cin >> a >> n >> b;

	//?a???n???????????value
	length = strlen(n);

	for (i = 0; i < length; i++) {
		product = 1;

		//?n[i]?????A-Z????????10-35
		if (n[i] >= 65 && n[i] <= 90) {
			temp = n[i] - 55;
		}

		//?n[i]?????????????10-35
		else if (n[i] >= 97 && n[i] <= 122) {
			temp = n[i] - 87;
		}

		//?n[i]?'0'-'9'????????0-9
		else {
			temp = n[i] - 48;
		}

		//???????value
		for (j = 0; j < length - i - 1; j++) {
			product *= a;
		}
		value += temp * product;
	}

	//?value???b???????????
	if (value == 0) {

		//??n=0????0?????
		cout << "0" << endl;
		return 0;

	} else {
		//?n??0???value??b?????????????m?
		char m[101];
		for (i = 0;; i++) {
			temp = value % b;
			if (value == 0) {
				break;
			} else if (temp >= 0 && temp <= 9) {
				m[i] = temp + 48;
			} else {
				m[i] = temp + 55;
			}
			value /= b;
		}

		//?m????????
		length = i;
		for (i = length - 1; i >= 0; i--) {
			cout << m[i];
		}
	}

	return 0; //????
}
