import java.util.*; import java.io.*; import java.math.*; class Main{ // 0になったら終了? void solve(){ long l = nl() , r = nl() , C = nl(); long min = Lnf; for(long i = l ; i <= r ; i ++ ) { long over = (i * C / 1000) + 1; min = Math.min(min,(1000 * over - C * i)%1000); if(min == 0) break; } output.print(min); } // for(int i = 0 ; i < n ; i ++ ) { // output.print(" "); // } // for(int i = 0 ; i < H ; i ++ ) { // for(int j = 0 ; j < W ; j ++ ) { // output.print(" "); // } // output.println(); // } /* 以下、ライブラリ等 */ private static PrintWriter output; private static FastScanner fs ; private static Scanner sc; private static final int Inf = 1000000000; private static final long Lnf = 1000000000000000000L; private static final String yes = "Yes"; private static final String no = "No"; //private static final long MOD = 1000000007; //private static final long MOD = 998244353 ; private static int ni() { return fs.nextInt(); } private static long nl() { return fs.nextLong(); } private static double nd() { return fs.nextDouble(); } private static String ns() { return fs.next(); } private static char nc() { return fs.next().charAt(0); } private static BigInteger bi() { return sc.nextBigInteger(); } private static BigDecimal bd() { return sc.nextBigDecimal(); } private static String cut(String S , int begin, int end) { return S.substring(begin,end); } private static char cut(String S , int idx) { return S.charAt(idx); } private static String tos(int val) { return Integer.toString(val); } private static String tos(long val) { return Long.toString(val); } private static int toi(String S) { return Integer.parseInt(S); } private static long tol(String S) { return Long.parseLong(S); } private static int min(int a , int b) { return (int)Math.min(a,b); } private static long min(long a , long b) { return (long)Math.min(a,b); } private static int max(int a , int b) { return (int)Math.max(a,b); } private static long max(long a , long b) { return (long)Math.max(a,b); } private static int abs(int a , int b) { return (int)Math.abs(a-b); } private static long abs(long a , long b) { return (long)Math.abs(a-b); } private static String t_n(int n , int m) { return Integer.toString(n,m); } private static int n_t(String n , int m) { return Integer.parseInt(n,m); } // i⌒i //     | |(゚)(゚) //     | |彡 と //     | |_ノ  ー、 //    (ミ)、 !フ / //    ¢\二二二__ノ //       |  / //      / ソ⌒ 、ヽ //     ( <   ヽ ) //     ⊂_)  (_つ private static int [] IntArray(int size) { final int [] array = new int [size]; for(int i = 0 ; i < size ; i ++ ) { array[i] = ni(); } return array; } private static long [] LongArray(int size) { long [] array = new long [size]; for(int i = 0 ; i < size ; i ++ ) { array[i] = nl(); } return array; } private static double [] DoubleArray(int size) { double [] array = new double [size]; for(int i = 0 ; i < size ; i ++ ) { array[i] = nd(); } return array; } private static String [] StringArray(int size) { String [] array = new String [size]; for(int i = 0 ; i < size ; i ++ ) { array[i] = ns(); } return array; } private static char [] CharArray(int size) { char [] array = ns().toCharArray(); return array; } private static int [][] IntArray(int sizeI , int sizeJ) { int [][] array = new int [sizeI][sizeJ]; for(int i = 0 ; i < sizeI ; i ++ ) for(int j = 0 ; j < sizeJ ; j ++ ) { array[i][j] = ni(); } return array; } private static long [][] LongArray(int sizeI , int sizeJ) { long [][] array = new long [sizeI][sizeJ]; for(int i = 0 ; i < sizeI ; i ++ ) for(int j = 0 ; j < sizeJ ; j ++ ) { array[i][j] = nl(); } return array; } private static double [][] DoubleArray(int sizeI , int sizeJ) { double [][] array = new double [sizeI][sizeJ]; for(int i = 0 ; i < sizeI ; i ++ ) for(int j = 0 ; j < sizeJ ; j ++ ) { array[i][j] = nd(); } return array; } private static String [][] StringArray(int sizeI , int sizeJ) { String [][] array = new String [sizeI][sizeJ]; for(int i = 0 ; i < sizeI ; i ++ ) for(int j = 0 ; j < sizeJ ; j ++ ) { array[i][j] = ns(); } return array; } private static char [][] CharArray(int sizeI , int sizeJ) { char [][] array = new char [sizeI][sizeJ]; for(int i = 0 ; i < sizeI ; i ++ ) { array[i] = ns().toCharArray(); } return array; } public static void main(String[] args){ output = new PrintWriter(System.out); fs = new FastScanner(); sc = new Scanner(System.in); new Main().solve(); output.flush(); } ////////////////// // My Library // ////////////////// private static int upper_bound(Integer [] array , int key) { return ~Arrays.binarySearch(array, key, (x,y)->x.compareTo(y)>0?1:-1); } private static int lower_bound(Integer [] array , int key) { return ~Arrays.binarySearch(array, key, (x,y)->x.compareTo(y)>=0?1:-1); } } /* 順列生成 */ class Permutation { ArrayList perm_list ; private int [] perm ; private int [] tmp ; private int [] used ; private int size = 0; private int len = 1; private int cur = 0; public Permutation(int [] base) { this.perm_list = new ArrayList(); this.perm = new int[base.length]; this.tmp = new int[base.length]; this.used = new int[base.length]; len = 1; size = base.length; System.arraycopy(base, 0, perm, 0, size); for(int i = base.length ; i > 0 ; i -- ) len *= i; for(int i = 0 ; i < len ; i ++ ) perm_list.add(new int[base.length]); } public void next_permutation(int idx){ if(idx == size) { for(int i = 0 ; i < size ; i ++ ) { perm_list.get(cur)[i] = tmp[i]; } cur++; return; } for(int i=0;i parent */ public void unite(int x, int y) { int xRoot = find(x); int yRoot = find(y); if (xRoot == yRoot) { return; } if (rank[xRoot] > rank[yRoot]) { parent[yRoot] = xRoot; } else if (rank[xRoot] < rank[yRoot]) { parent[xRoot] = yRoot; } else { parent[xRoot] = yRoot; rank[xRoot]++; size[yRoot] += size[xRoot]; } } } /* 強連結成分分解 */ class SCC { private boolean [] check ; private List> edge ; private List> revEdge ; private int count ; private int [] vr ; int [] group ; /* * group[i] = 0 -> 強連結成分であるが親でない。 * group[i] = 1 -> 強連結成分でない * group[i] > 1 -> 強連結成分内の頂点数を表し、iが親である。 */ private int groupNum ; /* * 連結成分数 (頂点数1も含む) */ public SCC(int n) { this.check = new boolean[n]; this.edge = new ArrayList<>(); this.revEdge = new ArrayList<>(); this.count = 0 ; this.vr = new int[n]; this.group = new int[n]; this.groupNum = 0 ; for(int i = 0 ; i < n ; i ++ ) { edge.add(new ArrayList<>()); revEdge.add(new ArrayList<>()); } } public void addEdge(int a , int b) { edge.get(a).add(b); revEdge.get(b).add(a); } public int getGroups(){ return this.groupNum; } public void start() { int n = group.length; for(int i = 0 ; i < n ; i ++ ) { if(!check[i]) { First(i); } } Arrays.fill(check,false); for(int i = n - 1 ; i >= 0 ; i -- ) { if(!check[vr[i]]) { Second(vr[i], groupNum++); } } } public void First(int now) { check[now] = true; for(int i : edge.get(now)) { if(!check[i]) { First(i); } } vr[count++] = now; } public void Second(int now,int groupNum) { check[now] = true; group[groupNum]++; for(int i : revEdge.get(now)) { if(!check[i]) { Second(i, groupNum); } } } } class FastScanner { private final InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private boolean hasNextByte() { if (ptr < buflen) { return true; }else{ ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;} private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;} public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();} public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while(isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while(true){ if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; }else if(b == -1 || !isPrintableChar(b)){ return minus ? -n : n; }else{ throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next());} }