N,K=map(int, input().split()) 

def change(N,shinsu):
    keta=0
    for i in range(10**9):
        if N<shinsu**i:
             keta+=i
             break
    ans=[0]*keta
    check=0
    for i in range(1,keta+1):
        j=N//(shinsu**(keta-i))
        ans[check]=j
        check+=1
        N-=(j)*(shinsu**(keta-i))
    return ans

print(len(change(N,K))) N,K=map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split K def change(N,shinsu):
    keta=0
    for i in range(10**9):
        if N<shinsu**i:
             keta+=i
             break
    ans=[0]*keta
    check=0
    for i in range(1,keta+1):
        j=N//(shinsu**(keta-i))
        ans[check]=j
        check+=1
        N-=(j)*(shinsu**(keta-i))
    return ans change keta=0 keta 0 for i in range(10**9):
        if N<shinsu**i:
             keta+=i
             break
     i range(10**9) range 10**9 10 9 if N<shinsu**i:
             keta+=i
             break
     N<shinsu**i N shinsu**i shinsu i keta+=i keta i break ans=[0]*keta ans [0]*keta [0] 0 keta check=0 check 0 for i in range(1,keta+1):
        j=N//(shinsu**(keta-i))
        ans[check]=j
        check+=1
        N-=(j)*(shinsu**(keta-i))
     i range(1,keta+1) range 1 keta+1 keta 1 j=N//(shinsu**(keta-i)) j N//(shinsu**(keta-i)) N shinsu**(keta-i) shinsu keta-i keta i ans[check]=j ans[check] ans check j check+=1 check 1 N-=(j)*(shinsu**(keta-i)) N (j)*(shinsu**(keta-i)) j shinsu**(keta-i) shinsu keta-i keta i return ans ans N N shinsu shinsu print(len(change(N,K))) print len(change(N,K)) len change(N,K) change N K K=map(int, input().split()) map(int, input().split()) K def change(N,shinsu):
    keta=0
    for i in range(10**9):
        if N<shinsu**i:
             keta+=i
             break
    ans=[0]*keta
    check=0
    for i in range(1,keta+1):
        j=N//(shinsu**(keta-i))
        ans[check]=j
        check+=1
        N-=(j)*(shinsu**(keta-i))
    return ans def change(N,shinsu):
    keta=0
    for i in range(10**9):
        if N<shinsu**i:
             keta+=i
             break
    ans=[0]*keta
    check=0
    for i in range(1,keta+1):
        j=N//(shinsu**(keta-i))
        ans[check]=j
        check+=1
        N-=(j)*(shinsu**(keta-i))
    return ans change N,K=map(int, input().split()) map(int, input().split()) N
N,K=map(int, input().split()) 

def change(N,shinsu):
    keta=0
    for i in range(10**9):
        if N<shinsu**i:
             keta+=i
             break
    ans=[0]*keta
    check=0
    for i in range(1,keta+1):
        j=N//(shinsu**(keta-i))
        ans[check]=j
        check+=1
        N-=(j)*(shinsu**(keta-i))
    return ans

print(len(change(N,K)))