import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int l = sc.nextInt(); int r = sc.nextInt(); int c = sc.nextInt(); if(l + 2001 < r) r = l + 1002; long min = Long.MAX_VALUE; for(long i = l; i <= r; i++){ long k = i * c % 1000; min = Math.min(k,min); } System.out.println(min); } }