Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has n rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is d rubles, and one euro costs e rubles.

Recall that there exist the following dollar bills: 1, 2, 5, 10, 20, 50, 100, and the following euro bills — 5, 10, 20, 50, 100, 200 (note that, in this problem we do not consider the 500 euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.

Help him — write a program that given integers n, e and d, finds the minimum number of rubles Andrew can get after buying dollar and euro bills.

Input

The first line of the input contains one integer n (1 ≤ n ≤ 10^8) — the initial sum in rubles Andrew has. 

The second line of the input contains one integer d (30 ≤ d ≤ 100) — the price of one dollar in rubles. 

The third line of the input contains integer e (30 ≤ e ≤ 100) — the price of one euro in rubles.

Output

Output one integer — the minimum number of rubles Andrew can have after buying dollar and euro bills optimally.

Examples

Input


100
60
70


Output


40


Input


410
55
70


Output


5


Input


600
60
70


Output


0

Note

In the first example, we can buy just 1 dollar because there is no 1 euro bill.

In the second example, optimal exchange is to buy 5 euro and 1 dollar.

In the third example, optimal exchange is to buy 10 dollars in one bill.
import java.util.*;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import static java.lang.Math.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;

public class In {
    static final int[] num_to_bits = new int[] { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 };
    static final Scanner sc=new Scanner(System.in);
    static final PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] args) {
        // int[] x={2,4,6};
         //long x = sc.nextLong();
         //while (x-- > 0) {
        // int n = sc.nextInt();
        // int[] a = new int[n];
        // for (int i = 0; i < a.length; i++) {
        // a[i] = sc.nextInt();
        // }
        // solve(n, a);

        // }
        
            
        //}
        
        long a=sc.nextLong();long b=sc.nextLong(),c=sc.nextLong();
        if(a%b==0)
            {
                System.out.println(0);
                return;
            }
            long ans=a%b;
            long i=a/(c*5L);
            while(i-->0){
                ans = min(ans, a % b);
                a-=(c*5L);
  
            }
        System.out.println(min(ans, a%b));

        
        sc.close();
        out.close();
    }
       

    // static int[] v = new int[6 + 1];
    // static public int solve(int A, ArrayList<Integer> B) {

    // for (int i = 0; i < B.size(); i++) {
    // v[B.get(i).intValue()]=1;
    // }
    // int as=0;
    // Collections.sort(B);
    // int ans = 0;
    // for (int i = 0; i < B.size(); i++) {
    // if(!(i+1<B.size()))
    // continue;
    // if(i<A-1&&B.get(i+1)==1+i)
    // continue;
    // B.add(i+1);
    // v[B.get(i)] = 1;
    // ans+=solve(A,B)+1;
    // }
    // int a;
    // return as+1;
    // }

    // // static int findRank(String A) {
    // // long ans = 0;
    // // int i = 0;
    // // for (i = 0; i < A.length(); i++) {
    // // char a = A.charAt(i);
    // // long c = 0;
    // // for (int j = i; j < A.length(); j++) {
    // // if (a > A.charAt(j))
    // // c++;
    // // }
    // // Vector<Long> v = new Vector<Long>(52);
    // // for (int ii = 0; ii < 52; ii++) {
    // // v.add(0L);
    // // }
    // // for (int j = i; j < A.length(); j++) {
    // // int index;
    // // if (A.charAt(j) >= 'A' && A.charAt(j) <= 'Z') {
    // // index = (int) (A.charAt(j) - 'A');
    // // } else {
    // // index = (int) (A.charAt(j) - 'a' + 26);
    // // }
    // // Long obj = v.get(index);
    // // obj++;
    // // v.setElementAt(obj, index);
    // // }
    // // long d_fac = 1;
    // // for (int ii = 0; ii < 52; ii++) {
    // // long n4 = v.get(ii);
    // // d_fac *= factorial(n4);
    // // }
    // // d_fac = po(d_fac, mod - 2L, mod);
    // // if (c <= 0)
    // // continue;
    // // long n = A.length() - 1 - i;
    // // long n1 = c * factorial(n) % mod;
    // // ans += (n1 * d_fac) % mod;
    // // }
    // // return (int) ((ans + 1) % mod);
    // // }

    static long factorial(long n) {

        // single line to find factorial
        return (n == 1L || n == 0L) ? 1L : n * factorial(n - 1) % 1000003L;

    }

    public static int[] int2Array(int num) {
        return Integer.toString(num).chars().map(c -> c - '0').toArray();
    }

    static long modexp(long x, long y, long p) {
        long res = 1;
        x = x % p;
        while (y > 0) {
            if ((y & 1) == 1)
                res = (res * x) % p;
            y = y >> 1;
            x = (x * x) % p;
        }
        return res;
    }

    public static ArrayList<Integer> arr2arrlist(int arr[]) {
        ArrayList<Integer> array_list = new ArrayList<Integer>();

        // Using add() method to add elements in array_list
        for (int i = 0; i < arr.length; i++)
            array_list.add(new Integer(arr[i]));
        return array_list;
    }

    public static void sortbyColumn(int arr[][], int col) {
        // Using built-in sort function Arrays.sort
        Arrays.sort(arr, new Comparator<int[]>() {

            @Override
            // Compare values according to columns
            public int compare(final int[] entry1, final int[] entry2) {

                // To sort in descending order revert
                // the '>' Operator
                if (entry1[col] > entry2[col])
                    return 1;
                else
                    return -1;
            }
        }); // End of function call sort().
    }
    
//     public static void sortbyColumn(ArrayList<ArrayList<Integer>> arr, int col) {

//         Collections.sort(arr, (entry1, entry2) -> {

//             Integer q = entry1.get(0);
//             Integer q1 = entry2.get(0);
//             if ((q) > (q1))
//                 return 1;
//             else
//                 return -1;
//         });
//     }

    
    static int countSetBits(int n) {
        int count = 0;
        while (n > 0) {
            n &= (n - 1);
            count++;
        }
        return count;
    }

    static int countSetBitsRec(int num) {
        int nibble = 0;
        if (0 == num)
            return num_to_bits[0];

        // Find last nibble
        nibble = num & 0xf;

        // Use pre-stored values to find count
        // in last nibble plus recursively add
        // remaining nibbles.
        return num_to_bits[nibble] + countSetBitsRec(num >> 4);
    }
}

class Pair implements Comparable<Pair> {
    public final int index;
    public final int value;

    public Pair(int index, int value) {
        this.index = index;
        this.value = value;
    }

    @Override
    public int compareTo(Pair other) {
        // multiplied to -1 as the author need descending sort order
        return Integer.valueOf(this.value).compareTo(other.value);
    }
}

class Print {
    private final BufferedWriter bw;

    public Print() {
        bw = new BufferedWriter(new OutputStreamWriter(System.out));
    }

    public void print(String str) throws IOException {
        bw.append(str);
    }

    public void printLine(String str) throws IOException {
        print(str);
        bw.append("\n");
    }

    public void close() throws IOException {
        bw.close();
    }
}

class Scan {
    private byte[] buf = new byte[1024];
    private int index;
    private InputStream in;
    private int total;

    public Scan() {
        in = System.in;
    }

    public int scan() throws IOException {
        if (total < 0)
            throw new InputMismatchException();
        if (index >= total) {
            index = 0;
            total = in.read(buf);
            if (total <= 0)
                return -1;
        }
        return buf[index++];
    }

    public int scanInt() throws IOException {
        int integer = 0;
        int n = scan();
        while (isWhiteSpace(n))
            n = scan();
        int neg = 1;
        if (n == '-') {
            neg = -1;
            n = scan();
        }
        while (!isWhiteSpace(n)) {
            if (n >= '0' && n <= '9') {
                integer *= 10;
                integer += n - '0';
                n = scan();
            } else
                throw new InputMismatchException();
        }
        return neg * integer;
    }

    public double scanDouble() throws IOException {
        double doub = 0;
        int n = scan();
        while (isWhiteSpace(n))
            n = scan();
        int neg = 1;
        if (n == '-') {
            neg = -1;
            n = scan();
        }
        while (!isWhiteSpace(n) && n != '.') {
            if (n >= '0' && n <= '9') {
                doub *= 10;
                doub += n - '0';
                n = scan();
            } else
                throw new InputMismatchException();
        }
        if (n == '.') {
            n = scan();
            double temp = 1;
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    temp /= 10;
                    doub += (n - '0') * temp;
                    n = scan();
                } else
                    throw new InputMismatchException();
            }
        }
        return doub * neg;
    }

    public String scanString() throws IOException {
        StringBuilder sb = new StringBuilder();
        int n = scan();
        while (isWhiteSpace(n))
            n = scan();
        while (!isWhiteSpace(n)) {
            sb.append((char) n);
            n = scan();
        }
        return sb.toString();
    }

    private boolean isWhiteSpace(int n) {
        if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
            return true;
        return false;
    }
}