import java.util.Scanner; class Main{ public static void main(String[] args) { Scanner scan=new Scanner(System.in); int n=scan.nextInt(); scan.close(); System.out.print(n%123456); } }