#include<cstdio>
#include<cstring>
#include<iostream>
#define K 10000
using namespace std ;
char a[1100000 ];
struct st{
long long s[5100 ],tot;
void init(){
memset (s,0 ,sizeof s);
tot=1 ;
}
void chu(int d){
for (int i=tot;i>=1 ;i--)
s[i-1 ]+=1l l*s[i]%d*K,s[i]=s[i]/d;
while (s[tot]==0 ) tot--;
}
void print(){
printf ("%lld" ,s[tot]);
for (int i=tot-1 ;i>=1 ;i--) printf ("%04lld" ,s[i]);
printf ("\n" );
}
}c;int d;
int k=1 ,n,m;
int main(){
cin >>a+1 >>d;
n=strlen (a+1 );
c.init();
for (int i=n;i>=1 ;i--) {
if (k==K) k=1 ,c.tot++;
c.s[c.tot]+=k*(a[i]-'0' );
k*=10 ;
}
c.chu(d);
c.print();
}
#include<cstdio>
#include<cstring>
#include<iostream>
#define K 10000
using namespace std ;
char a[1100000 ],b[1100000 ];
struct st{
int s[11000 ],tot;
void init(){
memset (s,0 ,sizeof s);
tot=1 ;
}
st operator -(const st&b)const {
st ans;ans.init();ans.tot=max(tot,b.tot);
for (int i=1 ;i<=ans.tot;i++)
ans.s[i]=s[i]-b.s[i];
for (int i=1 ;i<=ans.tot;i++)
if (ans.s[i]<0 ) ans.s[i]+=K,ans.s[i+1 ]-=1 ;
while (ans.s[ans.tot]==0 ) ans.tot--;
return ans;
}
void print(){
printf ("%d" ,s[tot]);
for (int i=tot-1 ;i>=1 ;i--) printf ("%04d" ,s[i]);
printf ("\n" );
}
}c,d;
int k=1 ,n,m;
int main(){
cin >>a+1 >>b+1 ;
n=strlen (a+1 ),m=strlen (b+1 );
c.init(),d.init();
for (int i=n;i>=1 ;i--) {
if (k==K) k=1 ,c.tot++;
c.s[c.tot]+=k*(a[i]-'0' );
k*=10 ;
}
k=1 ;
for (int i=m;i>=1 ;i--) {
if (k==K) k=1 ,d.tot++;
d.s[d.tot]+=k*(b[i]-'0' );
k*=10 ;
}
st ans;
ans.init();
if (n>m)
ans=c-d;
else if (n<m) printf ("-" ),ans=d-c;
else if (n==m){
for (int i=1 ;i<=max(c.tot,d.tot);i++)
if (c.s[i]>d.s[i])
ans=c-d;
else if (c.s[i]<d.s[i])
printf ("-" ),ans=d-c;
}
ans.print();
}
#include<cstdio>
#include<cstring>
#include<iostream>
#define K 10000
using namespace std ;
char a[1100000 ],b[1100000 ];
struct st{
int s[510 ],tot;
void init(){
memset (s,0 ,sizeof s);
tot=1 ;
}
st operator +(const st&b)const {
st ans;ans.init();ans.tot=max(tot,b.tot);
for (int i=1 ;i<=ans.tot;i++)
ans.s[i]=s[i]+b.s[i];
for (int i=1 ;i<=ans.tot;i++)
ans.s[i+1 ]+=(ans.s[i])/K,ans.s[i]=(ans.s[i])%K;
if (ans.s[ans.tot+1 ]) ans.tot++;
return ans;
}
void print(){
printf ("%d" ,s[tot]);
for (int i=tot-1 ;i>=1 ;i--) printf ("%04d" ,s[i]);
printf ("\n" );
}
}c,d;
int k=1 ,n,m;
int main(){
cin >>a+1 >>b+1 ;
n=strlen (a+1 ),m=strlen (b+1 );
c.init(),d.init();
for (int i=n;i>=1 ;i--) {
if (k==K) k=1 ,c.tot++;
c.s[c.tot]+=k*(a[i]-'0' );
k*=10 ;
}
k=1 ;
for (int i=m;i>=1 ;i--) {
if (k==K) k=1 ,d.tot++;
d.s[d.tot]+=k*(b[i]-'0' );
k*=10 ;
}
st ans=c+d;
ans.print();
}