import java.math.*; import java.util.*; import java.io.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(new BufferedInputStream(System.in)); BigInteger p,m,ans; int b; while ( cin.hasNext() ) { b = cin.nextInt(); if ( b == 0 ) break; p = cin.nextBigInteger(b); m = cin.nextBigInteger(b); ans = p.mod(m); System.out.println(ans.toString(b)); } } }