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(1000 < r - l)r = l + 1000; 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); } }