import java.io.*; import java.math.*; import java.util.*; public class Main { public static void main(String args[]) { Scanner cin=new Scanner(System.in); int a; BigInteger x,y; String str; while(cin.hasNextInt()) { a=cin.nextInt(); if(a==0) break; x=cin.nextBigInteger(a); y=cin.nextBigInteger(a); x=x.mod(y); str=x.toString(a); System.out.println(str); } } }