uses crt;
var n:longint;
m,i,d,t,x,y:integer;
st:string;
begin
clrscr;
repeat
write('Nhap n='); readln(n);
write('Nhap m='); readln(m);
until (0<=n) and (0<m) and (m<=10);
str(n,st);
d:=length(st);
t:=0;
for i:=d-m+1 to d do
begin
val(st[i],x,y);
t:=t+x;
end;
writeln('Tong ',m,' chu so tan cung cua ',n,' la: ',t);
readln;
end.