#include #include #include #include using namespace std; const int N = 105; int a[N]; char s[N * 2]; int ans[N * 2]; int main() { int n, b; while (scanf("%d%d", &n, &b) != EOF) { memset(ans, 0, sizeof(ans)); int l = 0; for (int i = 1; i <= n; ++i) { scanf("%s", s + 1); int l = strlen(s + 1); int t = l; for (int j = 201; j >= 201 - l + 1 && t >= 1; --j, --t) { int x; if (s[t] >= '0' && s[t] <= '9') x = s[t] - '0'; else if (s[t] >= 'a' && s[t] <= 'z') x = s[t] - 'a' + 10; ans[j] = ans[j] + x; if (ans[j] >= b) ans[j] %= b; } } int i = 1; for (; i <= 201; ++i) { if (!ans[i] && i != 201) continue; break; } for (int j = i; j <= 201; ++j) { if (ans[j] > 9) { int x = ans[j] - 10; printf("%c", x + 'a'); } else printf("%d", ans[j]); } puts(""); } return 0; }