#include <stdio.h>
#include <string.h>

void itob(int n, char *s, int b) {
    int i = 0;
    int sign = n;

    if (sign < 0) {
        n = -n;
    }

    do {
        int digit = n % b;
        s[i++] = (digit < 10) ? digit + '0' : digit - 10 + 'a';
        n /= b;
    } while (n > 0);

    if (sign < 0) {
        s[i++] = '-';
    }
    
    s[i] = '\0';

    int start = 0;
    int end = strlen(s) - 1;
    while (start < end) {
        char temp = s[start];
        s[start] = s[end];
        s[end] = temp;
        start++;
        end--;
    }
}

int main() {
    int n, b;
    char s[100];

    scanf("%d %d", &n, &b);

    itob(n, s, b);

    printf("%s\n", s);

    return 0;
}
