//土尔逊Torson 编写于2023/5/05
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <vector>

using namespace std;

string Add06301(string A, string B) {  //两个巨量整数求和函数 用字符串处理精度计算
	int dif = A.size() - B.size();
	int Maxdis;
	if (dif >= 0) {
		for (int i = 0; i < dif; ++i) {
			B = '0' + B;
		}
		Maxdis = A.size();
	}
	else if (dif < 0) {
		dif = -dif;
		for (int i = 0; i < dif; ++i) {
			A = '0' + A;
		}
		Maxdis = B.size();
	}

	string tmp(Maxdis, '0');
	int carry = 0;
	for (int i = Maxdis - 1; i >= 0; --i) {
		int current = (A[i] - '0') + (B[i] - '0') + carry;
		tmp[i] = current % 10 + '0';
		carry = current / 10;
		//printf("%d %d %c %d %d \n", A[i]-'0',B[i]-'0',tmp[i],current, carry);
	}
	//printf("\n");

	if (carry != 0) {
		tmp = '1' + tmp;
	}

	return tmp;
}

char IntToChar06301(int x) { //整数转换成字符格式
	if (x < 10) {
		return x + '0';
	}
	else {
		return x - 10 + '0';
	}
}

int main() {
	string str;
	int n = 1;
	while (getline(cin, str)) {
		n = str[0] - '0'; //N 是需要转换成的 m 进制数
		if (0 == n) {
			break;
		}
		string A, B;
		int pos;
		str = str.substr(2);

		for (int i = 0; i < str.size() - 1; ++i) {
			if (' ' == str[i]) {
				pos = i;
			}
		}

		A = str.substr(0, pos);
		B = str.substr(pos + 1);

		string sum;
		sum = Add06301(A, B);
		vector<char> answer;
		long long number = stod(sum);
		while (number != 0) { //转换 m 进制
			answer.push_back(IntToChar06301(number % n));
			number /= n;
		}

		if (sum[0] == '0') {
			answer.push_back('0');
		}
		//printf("%s\n", str.c_str());
		//printf("%s %d\n", A.c_str(),A.size());
		//printf("%s %d\n", B.c_str(),B.size());
		//for (int i = 0; i < A.size(); ++i) {
		//	printf("%d", A[i] - '0');
		//}
		//printf("\n");
		//printf("%s\n", sum.c_str());
		//printf("%c\n", answer[0]);
		for (int i = answer.size() - 1; i >= 0; --i) {
			printf("%c", answer[i]);
		}
		printf("\n");
	}
	//printf("Over\n");
	system("pause");
	return EXIT_SUCCESS;
}
// 64 位输出请用 printf("%lld")