#include <iostream>
#include <cstdlib>
using namespace std;
typedef int ElementType;
typedef struct Snode
{
ElementType x;
struct Snode * next;
} Snode, *Ptr_snode;
typedef struct Stack
{
Snode* top;
int length;
} Stack;
void Init(Stack &s)
{
s.top = NULL;
s.length = 0;
}
void Push(Stack &s, ElementType x)
{
Ptr_snode p = (Ptr_snode) malloc( sizeof(Snode) );
p->x = x;
p->next = s.top;
s.top = p;
s.length++;
}
bool Pop(Stack &s)
{
if(s.top)
{
Ptr_snode t = s.top;
s.top = s.top->next;
free(t);
s.length--;
return true;
}
else
{
return false;
}
}
bool Top(Stack &s, ElementType &x)
{
if(s.top)
{
x = s.top->x;
return true;
}
else
{
return false;
}
}
bool Empty(Stack &s)
{
return s.top == NULL;
}
int main()
{
int n, d;
ios::sync_with_stdio(false);
while(cin>>n>>d){
Stack s;
Init(s);
if(n == 0)//向0致敬
{
cout<<0<<endl;
continue;
}
while(n)
{
Push(s, n % d);
n /= d;
}
while(!Empty(s))
{
int t;
Top(s, t);
cout<<t;
Pop(s);
}
cout<<'\n';
}
return 0;
}