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(100000 < r - l)r = l + 100000; long min = Long.MAX_VALUE; for(int i = l; i <= r; i++){ long k = i * c % 1000; min = Math.min(k,min); } System.out.println(min); } }