import java.io.*;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.InputMismatchException;
import java.util.Queue;

public class A1214 {

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        OutputWriter out = new OutputWriter(System.out);

        int n = in.readInt();
        int d = in.readInt();
        int e = in.readInt();

        int res = n;

        int t = 0;
        while (t * 5 * e <= n) {
            res = Math.min(res, (n - t * 5 * e) % d);
            t++;
        }

        out.print(res);

        out.flush();
        out.close();
    }

    //FAST IO
    private static class InputReader
    {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream)
        {
            this.stream = stream;
        }

        public int read()
        {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars)
            {
                curChar = 0;
                try
                {
                    numChars = stream.read(buf);
                } catch (IOException e)
                {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do
            {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String readString()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do
            {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public double readDouble()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.')
            {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, readInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.')
            {
                c = read();
                double m = 1;
                while (!isSpaceChar(c))
                {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, readInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public long readLong()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do
            {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c)
        {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next()
        {
            return readString();
        }

        public interface SpaceCharFilter
        {
            public boolean isSpaceChar(int ch);
        }
    }

    private static class OutputWriter
    {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream)
        {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer)
        {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects)
        {
            for (int i = 0; i < objects.length; i++)
            {
                if (i != 0)
                    writer.print(' ');
                writer.print(objects[i]);
            }
        }

        public void printLine(Object... objects)
        {
            print(objects);
            writer.println();
        }

        public void close()
        {
            writer.close();
        }

        public void flush()
        {
            writer.flush();
        }
    }
}


import java.util.Scanner;

public class Main {

	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int x=scan.nextInt();
		int y=scan.nextInt();
		y=y*5;
		int  min=Integer.MAX_VALUE;
		for(int i=0;i<=(n/x);i++)
		{
			for(int j=0;j<=(n/y);j++)
			{
				int lol=n-((i*x)+(j*y));
				if(lol<0)continue;
				min=Math.min(min,lol);
			}
		}
		System.out.println(min);

	}
}


import java.util.Scanner;

public class Main {

	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int x=scan.nextInt();
		int y=scan.nextInt();
		y=y*5;
		int  min=Integer.MAX_VALUE;
		for(int i=0;i<=(n/y);i++)
		{

				int lol=n-(i*y);
				lol/=x;
				int gg=n-((i*y)+(lol*x));
				if(lol<0)continue;
				min=Math.min(min,gg);

		}
		System.out.println(min);

	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;

public class Practice {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		int n= Integer.parseInt(br.readLine());
		int d=Integer.parseInt(br.readLine());
		int e=Integer.parseInt(br.readLine());
		int[] a= new int[13];
		a[0]=d;
		a[1]=2*d;
		a[2]=5*d;
		a[3]=10*d;
		a[4]=20*d;
		a[5]=50*d;
		a[6]=100*d;
		a[7]=5*e;
		a[8]=10*e;
		a[9]=20*e;
		a[10]=50*e;
		a[11]=100*e;
		a[12]=200*e;

		Arrays.sort(a);
		//System.out.println(Arrays.toString(a));
		for(int i=a.length-1; i>-1; i--)
		{
			if(n>=a[i])
			{
				n=n%a[i];
			}
			//System.out.println(n);
		}
		pw.print(n);
		pw.flush();
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;

public class Practice {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		int n= Integer.parseInt(br.readLine());
		int d=Integer.parseInt(br.readLine());
		int e=Integer.parseInt(br.readLine());
		e*=5;
		int amount=0;
		int nDollars=0;
		while(n>=d)
		{
			amount+=d;
			nDollars++;
			n-=d;
		}
		while(n>=e)
		{
			amount+=e;
			n-=e;
		}
		int min=n;
		while(nDollars>0)
		{
			nDollars--;
			amount-=d;
			n+=d;
			if(n>=e)
			{
				amount+=e;
				n-=e;
			}
			min=Math.min(min, n);
		}
		pw.print(min);
		pw.flush();
	}
}


import java.awt.*;
import java.util.*;
import java.io.*;
import java.math.*;
import java.util.ArrayList;

public class CP {
    public static void main(String[] args) throws Exception {
        /*new Thread(null, new Runnable() {
            @Override
            public void run() {
                try {
                    new Solver().solve();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, "Solver", 1l << 30).start();*/

        new Solver().solve();
    }
}

class Solver {
    final Helper hp;
    final int MAXN = 1000_006;
    final long MOD = (long) 1e9 + 7;

    Solver() {
        hp = new Helper(MOD, MAXN);
        hp.initIO(System.in, System.out);
    }

    void solve() throws Exception {
        int i, j, k;

        long N = hp.nextLong(), D = hp.nextLong(), E = hp.nextLong() * 5;
        long ans = N;

        for (i = 0; i * D <= N; ++i) {
            ans = Math.min(ans, (N - i * D) % E);
        }
        for (i = 0; i * E <= N; ++i) {
            ans = Math.min(ans, (N - i * E) % D);
        }
        hp.println(ans);

        hp.flush();
    }
}

class Helper {
    final long MOD;
    final int MAXN;

    public Helper(long mod, int maxn) {
        MOD = mod;
        MAXN = maxn;
    }

    public static int[] sieve;
    public static ArrayList<Integer> primes;

    public void setSieve() {
        primes = new ArrayList<>();
        sieve = new int[MAXN];
        int i, j;
        for (i = 2; i < MAXN; ++i)
            if (sieve[i] == 0) {
                primes.add(i);
                for (j = i; j < MAXN; j += i) {
                    sieve[j] = i;
                }
            }
    }

    public static long[] factorial;

    public void setFactorial() {
        factorial = new long[MAXN];
        factorial[0] = 1;
        for (int i = 1; i < MAXN; ++i) factorial[i] = factorial[i - 1] * i % MOD;
    }

    public long getFact(int n) {
        if (factorial == null) setFactorial();
        return factorial[n];
    }

    public long ncr(int n, int r) {
        if (r > n) return 0;
        if (factorial == null) setFactorial();
        long numerator = factorial[n];
        long denominator = factorial[r] * factorial[n - r] % MOD;
        return numerator * pow(denominator, MOD - 2, MOD) % MOD;
    }

    public long[] getLongArray(int size) throws Exception {
        long[] ar = new long[size];
        for (int i = 0; i < size; ++i) ar[i] = nextLong();
        return ar;
    }

    public int[] getIntArray(int size) throws Exception {
        int[] ar = new int[size];
        for (int i = 0; i < size; ++i) ar[i] = nextInt();
        return ar;
    }

    public String[] getStringArray(int size) throws Exception {
        String[] ar = new String[size];
        for (int i = 0; i < size; ++i) ar[i] = next();
        return ar;
    }

    public String joinElements(long[] ar) {
        StringBuilder sb = new StringBuilder();
        for (long itr : ar) sb.append(itr).append(" ");
        return sb.toString().trim();
    }

    public String joinElements(int[] ar) {
        StringBuilder sb = new StringBuilder();
        for (int itr : ar) sb.append(itr).append(" ");
        return sb.toString().trim();
    }

    public String joinElements(String[] ar) {
        StringBuilder sb = new StringBuilder();
        for (String itr : ar) sb.append(itr).append(" ");
        return sb.toString().trim();
    }

    public String joinElements(Object[] ar) {
        StringBuilder sb = new StringBuilder();
        for (Object itr : ar) sb.append(itr).append(" ");
        return sb.toString().trim();
    }

    public long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    public int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    public long max(long[] ar) {
        long ret = ar[0];
        for (long itr : ar) ret = Math.max(ret, itr);
        return ret;
    }

    public int max(int[] ar) {
        int ret = ar[0];
        for (int itr : ar) ret = Math.max(ret, itr);
        return ret;
    }

    public long min(long[] ar) {
        long ret = ar[0];
        for (long itr : ar) ret = Math.min(ret, itr);
        return ret;
    }

    public int min(int[] ar) {
        int ret = ar[0];
        for (int itr : ar) ret = Math.min(ret, itr);
        return ret;
    }

    public long sum(long[] ar) {
        long sum = 0;
        for (long itr : ar) sum += itr;
        return sum;
    }

    public long sum(int[] ar) {
        long sum = 0;
        for (int itr : ar) sum += itr;
        return sum;
    }

    public long pow(long base, long exp, long MOD) {
        base %= MOD;
        long ret = 1;
        while (exp > 0) {
            if ((exp & 1) == 1) ret = ret * base % MOD;
            base = base * base % MOD;
            exp >>= 1;
        }
        return ret;
    }

    static byte[] buf = new byte[2048];
    static int index, total;
    static InputStream in;
    static BufferedWriter bw;

    public void initIO(InputStream is, OutputStream os) {
        try {
            in = is;
            bw = new BufferedWriter(new OutputStreamWriter(os));
        } catch (Exception e) {
        }
    }

    public void initIO(String inputFile, String outputFile) {
        try {
            in = new FileInputStream(inputFile);
            bw = new BufferedWriter(new OutputStreamWriter(
                    new FileOutputStream(outputFile)));
        } catch (Exception e) {
        }
    }

    private int scan() throws Exception {
        if (index >= total) {
            index = 0;
            total = in.read(buf);
            if (total <= 0)
                return -1;
        }
        return buf[index++];
    }

    public String next() throws Exception {
        int c;
        for (c = scan(); c <= 32; c = scan()) ;
        StringBuilder sb = new StringBuilder();
        for (; c > 32; c = scan())
            sb.append((char) c);
        return sb.toString();
    }

    public int nextInt() throws Exception {
        int c, val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+')
            c = scan();
        for (; c >= '0' && c <= '9'; c = scan())
            val = (val << 3) + (val << 1) + (c & 15);
        return neg ? -val : val;
    }

    public long nextLong() throws Exception {
        int c;
        long val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+')
            c = scan();
        for (; c >= '0' && c <= '9'; c = scan())
            val = (val << 3) + (val << 1) + (c & 15);
        return neg ? -val : val;
    }

    public void print(Object a) throws Exception {
        bw.write(a.toString());
    }

    public void printsp(Object a) throws Exception {
        print(a);
        print(" ");
    }

    public void println() throws Exception {
        bw.write("\n");
    }

    public void println(Object a) throws Exception {
        print(a);
        println();
    }

    public void flush() throws Exception {
        bw.flush();
    }
}


import java.io.*;
import java.util.ArrayList;
import java.util.*;
import java.math.*;
import java.awt.*;

public class CP {
    public static void main(String[] args) throws Exception {
        /*new Thread(null, new Runnable() {
            @Override
            public void run() {
                try {
                    new Solver().solve();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, "Solver", 1l << 30).start();*/

        new Solver().solve();
    }
}

class Solver {
    final Helper hp;
    final int MAXN = 1000_006;
    final long MOD = (long) 1e9 + 7;

    Solver() {
        hp = new Helper(MOD, MAXN);
        hp.initIO(System.in, System.out);
    }

    void solve() throws Exception {
        int i, j, k;

        long N = hp.nextLong(), D = hp.nextLong(), E = hp.nextLong() * 5l;
        long ans = Long.MAX_VALUE;
        for (i = 1; i <= N; ++i) {
            long A = i, B = N - i;
            ans = Math.min(ans, A % D + B % E);
        }
        hp.println(ans);

        hp.flush();
    }
}

class Helper {
    final long MOD;
    final int MAXN;

    public Helper(long mod, int maxn) {
        MOD = mod;
        MAXN = maxn;
    }

    public static int[] sieve;
    public static ArrayList<Integer> primes;

    public void setSieve() {
        primes = new ArrayList<>();
        sieve = new int[MAXN];
        int i, j;
        for (i = 2; i < MAXN; ++i)
            if (sieve[i] == 0) {
                primes.add(i);
                for (j = i; j < MAXN; j += i) {
                    sieve[j] = i;
                }
            }
    }

    public static long[] factorial;

    public void setFactorial() {
        factorial = new long[MAXN];
        factorial[0] = 1;
        for (int i = 1; i < MAXN; ++i) factorial[i] = factorial[i - 1] * i % MOD;
    }

    public long getFact(int n) {
        if (factorial == null) setFactorial();
        return factorial[n];
    }

    public long ncr(int n, int r) {
        if (r > n) return 0;
        if (factorial == null) setFactorial();
        long numerator = factorial[n];
        long denominator = factorial[r] * factorial[n - r] % MOD;
        return numerator * pow(denominator, MOD - 2, MOD) % MOD;
    }

    public long[] getLongArray(int size) throws Exception {
        long[] ar = new long[size];
        for (int i = 0; i < size; ++i) ar[i] = nextLong();
        return ar;
    }

    public int[] getIntArray(int size) throws Exception {
        int[] ar = new int[size];
        for (int i = 0; i < size; ++i) ar[i] = nextInt();
        return ar;
    }

    public String[] getStringArray(int size) throws Exception {
        String[] ar = new String[size];
        for (int i = 0; i < size; ++i) ar[i] = next();
        return ar;
    }

    public String joinElements(long[] ar) {
        StringBuilder sb = new StringBuilder();
        for (long itr : ar) sb.append(itr).append(" ");
        return sb.toString().trim();
    }

    public String joinElements(int[] ar) {
        StringBuilder sb = new StringBuilder();
        for (int itr : ar) sb.append(itr).append(" ");
        return sb.toString().trim();
    }

    public String joinElements(String[] ar) {
        StringBuilder sb = new StringBuilder();
        for (String itr : ar) sb.append(itr).append(" ");
        return sb.toString().trim();
    }

    public String joinElements(Object[] ar) {
        StringBuilder sb = new StringBuilder();
        for (Object itr : ar) sb.append(itr).append(" ");
        return sb.toString().trim();
    }

    public long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    public int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    public long max(long[] ar) {
        long ret = ar[0];
        for (long itr : ar) ret = Math.max(ret, itr);
        return ret;
    }

    public int max(int[] ar) {
        int ret = ar[0];
        for (int itr : ar) ret = Math.max(ret, itr);
        return ret;
    }

    public long min(long[] ar) {
        long ret = ar[0];
        for (long itr : ar) ret = Math.min(ret, itr);
        return ret;
    }

    public int min(int[] ar) {
        int ret = ar[0];
        for (int itr : ar) ret = Math.min(ret, itr);
        return ret;
    }

    public long sum(long[] ar) {
        long sum = 0;
        for (long itr : ar) sum += itr;
        return sum;
    }

    public long sum(int[] ar) {
        long sum = 0;
        for (int itr : ar) sum += itr;
        return sum;
    }

    public long pow(long base, long exp, long MOD) {
        base %= MOD;
        long ret = 1;
        while (exp > 0) {
            if ((exp & 1) == 1) ret = ret * base % MOD;
            base = base * base % MOD;
            exp >>= 1;
        }
        return ret;
    }

    static byte[] buf = new byte[2048];
    static int index, total;
    static InputStream in;
    static BufferedWriter bw;

    public void initIO(InputStream is, OutputStream os) {
        try {
            in = is;
            bw = new BufferedWriter(new OutputStreamWriter(os));
        } catch (Exception e) {
        }
    }

    public void initIO(String inputFile, String outputFile) {
        try {
            in = new FileInputStream(inputFile);
            bw = new BufferedWriter(new OutputStreamWriter(
                    new FileOutputStream(outputFile)));
        } catch (Exception e) {
        }
    }

    private int scan() throws Exception {
        if (index >= total) {
            index = 0;
            total = in.read(buf);
            if (total <= 0)
                return -1;
        }
        return buf[index++];
    }

    public String next() throws Exception {
        int c;
        for (c = scan(); c <= 32; c = scan()) ;
        StringBuilder sb = new StringBuilder();
        for (; c > 32; c = scan())
            sb.append((char) c);
        return sb.toString();
    }

    public int nextInt() throws Exception {
        int c, val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+')
            c = scan();
        for (; c >= '0' && c <= '9'; c = scan())
            val = (val << 3) + (val << 1) + (c & 15);
        return neg ? -val : val;
    }

    public long nextLong() throws Exception {
        int c;
        long val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+')
            c = scan();
        for (; c >= '0' && c <= '9'; c = scan())
            val = (val << 3) + (val << 1) + (c & 15);
        return neg ? -val : val;
    }

    public void print(Object a) throws Exception {
        bw.write(a.toString());
    }

    public void printsp(Object a) throws Exception {
        print(a);
        print(" ");
    }

    public void println() throws Exception {
        bw.write("\n");
    }

    public void println(Object a) throws Exception {
        print(a);
        println();
    }

    public void flush() throws Exception {
        bw.flush();
    }
}


import java.io.*;
import java.util.ArrayList;
import java.util.*;
import java.math.*;
import java.awt.*;

public class CP {
    public static void main(String[] args) throws Exception {
        /*new Thread(null, new Runnable() {
            @Override
            public void run() {
                try {
                    new Solver().solve();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, "Solver", 1l << 30).start();*/

        new Solver().solve();
    }
}

class Solver {
    final Helper hp;
    final int MAXN = 1000_006;
    final long MOD = (long) 1e9 + 7;

    Solver() {
        hp = new Helper(MOD, MAXN);
        hp.initIO(System.in, System.out);
    }

    void solve() throws Exception {
        int i, j, k;

        long N = hp.nextLong(), D = hp.nextLong(), E = hp.nextLong() * 5l;
        long ans = Long.MAX_VALUE;
        for (i = 0; i <= N; ++i) {
            long A = i, B = N - i;
            ans = Math.min(ans, A % D + B % E);
        }
        hp.println(ans);

        hp.flush();
    }
}

class Helper {
    final long MOD;
    final int MAXN;

    public Helper(long mod, int maxn) {
        MOD = mod;
        MAXN = maxn;
    }

    public static int[] sieve;
    public static ArrayList<Integer> primes;

    public void setSieve() {
        primes = new ArrayList<>();
        sieve = new int[MAXN];
        int i, j;
        for (i = 2; i < MAXN; ++i)
            if (sieve[i] == 0) {
                primes.add(i);
                for (j = i; j < MAXN; j += i) {
                    sieve[j] = i;
                }
            }
    }

    public static long[] factorial;

    public void setFactorial() {
        factorial = new long[MAXN];
        factorial[0] = 1;
        for (int i = 1; i < MAXN; ++i) factorial[i] = factorial[i - 1] * i % MOD;
    }

    public long getFact(int n) {
        if (factorial == null) setFactorial();
        return factorial[n];
    }

    public long ncr(int n, int r) {
        if (r > n) return 0;
        if (factorial == null) setFactorial();
        long numerator = factorial[n];
        long denominator = factorial[r] * factorial[n - r] % MOD;
        return numerator * pow(denominator, MOD - 2, MOD) % MOD;
    }

    public long[] getLongArray(int size) throws Exception {
        long[] ar = new long[size];
        for (int i = 0; i < size; ++i) ar[i] = nextLong();
        return ar;
    }

    public int[] getIntArray(int size) throws Exception {
        int[] ar = new int[size];
        for (int i = 0; i < size; ++i) ar[i] = nextInt();
        return ar;
    }

    public String[] getStringArray(int size) throws Exception {
        String[] ar = new String[size];
        for (int i = 0; i < size; ++i) ar[i] = next();
        return ar;
    }

    public String joinElements(long[] ar) {
        StringBuilder sb = new StringBuilder();
        for (long itr : ar) sb.append(itr).append(" ");
        return sb.toString().trim();
    }

    public String joinElements(int[] ar) {
        StringBuilder sb = new StringBuilder();
        for (int itr : ar) sb.append(itr).append(" ");
        return sb.toString().trim();
    }

    public String joinElements(String[] ar) {
        StringBuilder sb = new StringBuilder();
        for (String itr : ar) sb.append(itr).append(" ");
        return sb.toString().trim();
    }

    public String joinElements(Object[] ar) {
        StringBuilder sb = new StringBuilder();
        for (Object itr : ar) sb.append(itr).append(" ");
        return sb.toString().trim();
    }

    public long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    public int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    public long max(long[] ar) {
        long ret = ar[0];
        for (long itr : ar) ret = Math.max(ret, itr);
        return ret;
    }

    public int max(int[] ar) {
        int ret = ar[0];
        for (int itr : ar) ret = Math.max(ret, itr);
        return ret;
    }

    public long min(long[] ar) {
        long ret = ar[0];
        for (long itr : ar) ret = Math.min(ret, itr);
        return ret;
    }

    public int min(int[] ar) {
        int ret = ar[0];
        for (int itr : ar) ret = Math.min(ret, itr);
        return ret;
    }

    public long sum(long[] ar) {
        long sum = 0;
        for (long itr : ar) sum += itr;
        return sum;
    }

    public long sum(int[] ar) {
        long sum = 0;
        for (int itr : ar) sum += itr;
        return sum;
    }

    public long pow(long base, long exp, long MOD) {
        base %= MOD;
        long ret = 1;
        while (exp > 0) {
            if ((exp & 1) == 1) ret = ret * base % MOD;
            base = base * base % MOD;
            exp >>= 1;
        }
        return ret;
    }

    static byte[] buf = new byte[2048];
    static int index, total;
    static InputStream in;
    static BufferedWriter bw;

    public void initIO(InputStream is, OutputStream os) {
        try {
            in = is;
            bw = new BufferedWriter(new OutputStreamWriter(os));
        } catch (Exception e) {
        }
    }

    public void initIO(String inputFile, String outputFile) {
        try {
            in = new FileInputStream(inputFile);
            bw = new BufferedWriter(new OutputStreamWriter(
                    new FileOutputStream(outputFile)));
        } catch (Exception e) {
        }
    }

    private int scan() throws Exception {
        if (index >= total) {
            index = 0;
            total = in.read(buf);
            if (total <= 0)
                return -1;
        }
        return buf[index++];
    }

    public String next() throws Exception {
        int c;
        for (c = scan(); c <= 32; c = scan()) ;
        StringBuilder sb = new StringBuilder();
        for (; c > 32; c = scan())
            sb.append((char) c);
        return sb.toString();
    }

    public int nextInt() throws Exception {
        int c, val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+')
            c = scan();
        for (; c >= '0' && c <= '9'; c = scan())
            val = (val << 3) + (val << 1) + (c & 15);
        return neg ? -val : val;
    }

    public long nextLong() throws Exception {
        int c;
        long val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+')
            c = scan();
        for (; c >= '0' && c <= '9'; c = scan())
            val = (val << 3) + (val << 1) + (c & 15);
        return neg ? -val : val;
    }

    public void print(Object a) throws Exception {
        bw.write(a.toString());
    }

    public void printsp(Object a) throws Exception {
        print(a);
        print(" ");
    }

    public void println() throws Exception {
        bw.write("\n");
    }

    public void println(Object a) throws Exception {
        print(a);
        println();
    }

    public void flush() throws Exception {
        bw.flush();
    }
}


import java.util.Scanner;

public class C_A {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        byte d = sc.nextByte();
        byte e = sc.nextByte();

        int min = n;

        for(int i = 0; (n - i*e*5) >= 0; ++i){
            if((n - i*e*5) % d < min && n - i*5*e >= 0){
                min = (n - i*e*5    ) % d;
            }
        }

        System.out.print(min);
    }
}


import java.util.Scanner;

public class C_A {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        byte d = sc.nextByte();
        byte e = sc.nextByte();

        int min = n;

        for(int i = 0; i < n; ++i){
            if((n - i*e*5) % d < min && n - i*5*e >= 0){
                min = (n - i*e*5    ) % d;
            }
        }

        System.out.print(min);
    }
}


import java.util.*;

public class Codechef {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int d=s.nextInt();
int e=s.nextInt();
int min=Integer.MAX_VALUE;
for(int i=0;i<=n/e;i+=5) {
	int a=n-i*e;
	a%=d;
	if(a==0)
	{
		System.out.println(a);
		return;
	}
	if(min>a)
		min=a;
}
System.out.println(min);
}

}


import java.util.*;

public class Codechef {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int d=s.nextInt();
int e=s.nextInt();
int min=Integer.MAX_VALUE;
for(int i=5;i<=n;i+=5) {
	int a=n-i*e;
	a%=d;
	if(a==0)
	{
		System.out.println(a);
		return;
	}
	if(min>a)
		min=a;
}
System.out.println(min);
}

}


import java.util.*;

public class Codechef {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int d=s.nextInt();
int e=s.nextInt();
int a=(n%d)%e;
int b=(n%e)%d;
System.out.println(Math.min(a,b));
}

}


import java.util.*;

public class Codechef {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int d=s.nextInt();
int e=s.nextInt();
int min=Integer.MAX_VALUE;
int[][] a=new int[n/d+1][n/(5*e)+1];
for(int i=0;i<a.length;i++) {
	for(int j=0;j<a[i].length;j++) {
		a[i][j]=n-(i*d+j*5*e);

		if(a[i][j]==0)
			{
			System.out.println(0);
			return;
			}
		min=Math.min(a[i][j], min);
	}
}
System.out.println(min);
}

}


import java.util.*;

public class Codechef {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int d=s.nextInt();
int e=s.nextInt();
int []ad= {1,2,5,10,20,50,100};
int []ae= {5,10,20,50,100,200};
int i=ae.length-1;
int j=ad.length-1;
while(n>0&&i>=0&&j>=0) {
int p=0;int k=0;

if(d*ad[j]<e*ae[i]) {
	p=e*ae[i];k=-1;
}
else {
	p=d*ad[j];k=-2;
}
while(n>=p) {
n-=p;
}

if(k==-1) {i--;}
else {j--;}
}
while(i>=0) {
int	p=e*ae[i];
	while(n>=p) {
		n-=p;
		}

	i--;
}
while(j>=0) {
int	p=d*ad[j];
	while(n>=p) {
		n-=p;
		}

	j--;
}
System.out.println(n);
}


import java.util.*;

public class Codechef {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int d=s.nextInt();
int e=s.nextInt();
int []ad= {1,2,5,10,20,50,100};
int []ae= {5,10,20,50,100,200};
int i=ae.length-1;
int j=ad.length-1;
while(n>0&&i>=0&&j>=0) {
int p=0;int k=0;

if(d*ad[j]<e*ae[i]) {
	p=e*ae[i];k=-1;
}
else {
	p=d*ad[j];k=-2;
}
while(n>=p) {
n-=p;
}

if(k==-1) {i--;}
else {j--;}
}
while(i>=0) {
int	p=e*ae[i];
	while(n>=p) {
		n-=p;
		}

	i--;
}
while(j>=0) {
int	p=d*ad[j];
	while(n>=p) {
		n-=p;
		}

	j--;
}
System.out.println(n);
}
}


//package Round583;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class typeA {
	public static void main(String[] args) {
		FastReader s = new FastReader();
		int n = s.nextInt();
		int d = s.nextInt();
		int e = s.nextInt();
		int a = n/d;
		int min_so_far = Integer.MAX_VALUE;
		for(int i=0;i<=a;i++) {
			int dol = i*d;
			int left = n-dol;
			int eur = left/e;
			int rem = eur%5;
			int spe = e*eur-(rem*e);
				left-=spe;
			if(left<min_so_far) {
				min_so_far = left;
			}
		}
		System.out.println(min_so_far);
	}
	static class FastReader

    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

}


//package Round583;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class typeA {
	public static void main(String[] args) {
		FastReader s = new FastReader();
		int n = s.nextInt();
		int d = s.nextInt();
		int e = s.nextInt();
		int gcd1 = 1;
		int gcd2 = 5;
		int a = n/d;
		int b = n/e;
		int min_so_far = Integer.MAX_VALUE;
		for(int i=0;i<=a;i++) {
			int dol = i*d;
			int left = n-dol;
			int eur = left/e;
			if(eur%5==0) {
				left-=(e*eur);
			}
			if(left<min_so_far) {
				min_so_far = left;
			}
		}
		System.out.println(min_so_far);
//		if(a>=1) {
//			int n2 = n;
//			left-=a*d;
//			n2-=a*d;
//			int b2 = n2/e;
//			if(b2%5==0) {
//			left-=b2*e;
//			}
//
//		}
//
//		if(b%5==0) {
//			int n2 = n;
//			left2-=b*e;
//			n2-=b*e;
//			int a2 = n2/d;
//			left2-=a2*d;
//		}
//		System.out.println(Math.min(left2,left));
	}
static class FastReader

    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

}


//package Round583;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class typeA {
	public static void main(String[] args) {
		FastReader s = new FastReader();
		int n = s.nextInt();
		int d = s.nextInt();
		int e = s.nextInt();
		int gcd1 = 1;
		int gcd2 = 5;
		int left = n;
		int left2 = n;
		int a = n/d;
		int b = n/e;
		if(a>=1) {
			int n2 = n;
			left-=a*d;
			n2-=a*d;
			int b2 = n2/e;
			if(b2%5==0) {
			left-=b2*e;
			}

		}

		if(b%5==0) {
			int n2 = n;
			left2-=b*e;
			n2-=b*e;
			int a2 = n2/d;
			left2-=a2*d;
		}
		System.out.println(Math.min(left2,left));
	}
static class FastReader

    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

}


import java.util.Scanner;

public class Solution {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        int d = in.nextInt();
        int e = in.nextInt();
        e *= 5;

        boolean[] flag = new boolean[n + 1];
        flag[n] = true;
        for (int i = n; i >= 0; --i) {
            if (flag[i]) {
                if (i >= d) flag[i - d] = true;
                if (i >= e) flag[i - e] = true;
            }
        }
        for (int i = 0; i <= n; ++i) {
            if (flag[i]) {
                System.out.println(i);
                break;
            }
        }
    }
}


import java.util.Scanner;

public class Solution {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        int d = in.nextInt();
        int e = in.nextInt();
        e *= 5;

        boolean[] flag = new boolean[n + 1];
        flag[n] = true;
        for (int i = n; i >= 0; --i) {
            if (flag[i]) {
                if (i >= d) flag[i - d] = true;
                if (i >= e) flag[i - e] = true;
            }
        }
        for (int i = 0; i< n; ++i) {
            if (flag[i]) {
                System.out.println(i);
                break;
            }
        }
    }
}


    import java.util.*;

    public class Exchange{
        static int sum(int d,int E,int N,int[] arr){
            if(arr[N]!=-1) return arr[N];
            if(d<=N&&E<=N){
                return arr[N]=Math.min(sum(d,E,N-d,arr),sum(d,E,N-E,arr));
            }
            else if(d<=N){
                return arr[N]=sum(d,E,N-d,arr);
            }
            else if(E<=N){
                return arr[N]=sum(d,E,N-E,arr);
            }
             return arr[N]=N;

        }
        public static void main(String[] args){
            Scanner scan = new Scanner(System.in);
            int N= scan.nextInt();
            int d = scan.nextInt();
            int arr[] = new int[N+1];
            for(int i=0;i<=N;i++) arr[i]=-1;
            int E= scan.nextInt();
            E=5*E;
            int val =sum(d,E,N,arr);
             System.out.println(val);

        }
    }


import java.util.*;

public class Exchange{

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N= scan.nextInt();
        int d = scan.nextInt();
        int arr[] = new int[N+1];
        arr[0]=0;
        int E= scan.nextInt();
        E*=5;
        for(int i=1;i<=N;i++){
            if(d<=i&&E<=i) arr[i]= Math.min(arr[i-d],arr[i-E]);
            else if(d<=i) arr[i]= arr[i-d];
            else if(E<=i) arr[i]= arr[i-E];
            else arr[i]=i;
        }

         System.out.println(arr[N]);

    }
}


import java.util.*;

public class Exchange{

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N= scan.nextInt();
        int d = scan.nextInt();
        int arr[] = new int[N+1];
        arr[0]=0;
        int E= scan.nextInt();
        for(int i=1;i<=N;i++){
            if(d<=i&&E<=i) arr[i]= Math.min(arr[i-d],arr[i-E]);
            else if(d<=i) arr[i]= arr[i-d];
            else if(E<=i) arr[i]= arr[i-E];
            else arr[i]=i;
        }

         System.out.println(arr[N]);

    }
}


import java.util.HashMap;
import java.util.Scanner;

public class ChatRoomCodeForces {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int R= scan.nextInt();
        int D= scan.nextInt();
        int E= scan.nextInt();
        int rDivided=R%D;
        int rdividee=R%(5*E);
        if(rdividee>D){
            rdividee=rdividee%D;
        }
        if(rDivided<rdividee){
            System.out.println(rDivided);
        }
        else{
            System.out.println(rdividee);
        }

    }
}


import java.util.*;

public class Exchange{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N= scan.nextInt();
        int d = scan.nextInt();
        int E= scan.nextInt();
        E=5*E;
        if(N<E){
            System.out.println(N%d);
        }
        else{
            int min = N%d;
            int val = N%E;
            val = val%d;
            min = Math.min(min,val);
            System.out.println(min);
        }

    }
}


import java.util.*;

public class Exchange{
    static int sum(int d,int E,int N,int[] arr){
        if(arr[N]!=-1) return arr[N];
        if(d<=N&&E<=N){
            return arr[N]=Math.min(sum(d,E,N-d,arr),sum(d,E,N-E,arr));
        }
        else if(d<=N){
            return arr[N]=sum(d,E,N-d,arr);
        }
        else if(E<=N){
            return arr[N]=sum(d,E,N-E,arr);
        }
         return arr[N]=N;

    }
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N= scan.nextInt();
        int d = scan.nextInt();
        int arr[] = new int[N+1];
        for(int i=0;i<=N;i++) arr[i]=-1;
        int E= scan.nextInt();
        int val =sum(d,E,N,arr);
         System.out.println(val);

    }
}


import java.util.Scanner;

public class BadgesCodeChef {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int b= scan.nextInt();
        int g= scan.nextInt();
        int n= scan.nextInt();
        int min=Math.min(b,g);
        int max= Math.max(b,g);
        if(b+g==n){
            System.out.println(1);
        }
        else if(n<=min){
            System.out.println(n+1);
        }
        else if(n>min &&n<max){
            System.out.println((b+g+1)-n);
        }
        else{
            System.out.println(min+1);
        }
    }
}


import java.util.*;

public class Exchange{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N= scan.nextInt();
        int d = scan.nextInt();
        int E= scan.nextInt();
        E=5*E;
        if(N<E){
            System.out.println(N%d);
        }
        else{
            int min = N%d;
            min%=E;
            int val = N%E;
            val = val%d;
            min = Math.min(min,val);
            System.out.println(min);
        }

    }
}


import java.io.*;
import java.util.*;
public class vk18
{
    public static void main(String[]st) throws Exception
    {
    	//Scanner scan=new Scanner(System.in);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        //String s[];
        int n,d,e,min1=Integer.MAX_VALUE,min2=9999990,i;
        n=Integer.parseInt(br.readLine());
        d=Integer.parseInt(br.readLine());
        e=Integer.parseInt(br.readLine());
        for(i=0;i*5*e<=n;i++) min1=Math.min(min1,(n-i*5*e)%d);
        System.out.println(min1);
    }
}


import java.io.*;
import java.util.*;
public class vk18
{
    public static void main(String[]st) throws Exception
    {
    	//Scanner scan=new Scanner(System.in);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        //String s[];
        int n,d,e,min1=9999990,min2=9999990;
        n=Integer.parseInt(br.readLine());
        d=Integer.parseInt(br.readLine());
        e=Integer.parseInt(br.readLine());
        min1=n%d;
        if(n>=5*e) { int p=n/(5*e); int diff=n-(p*5*e); min2=diff%d; }
        System.out.println(Math.min(min1,min2));
    }
}


import java.io.*;
import java.util.*;
import java.math.*;

public class optimalCurrency {
    static Scanner sc = new Scanner(System.in);
    static PrintWriter pw = new PrintWriter(System.out), pw2 = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        int n=sc.nextInt(),d=sc.nextInt(),e=sc.nextInt();
        e=e*5;
        int min=Integer.MAX_VALUE;
        for(int div=0;div*d<=n;div++){
            int ediv=(n-div*d)/e;
            min=Math.min(n-div*d-e*ediv,min);
        }
        System.out.println(min);
    }
    public static int LCM(int i,int j){
        return (i*j)/gcd(i,j);
    }
    public static <E> void print2D(E[][] arr) {
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                pw.println(arr[i][j]);
            }
        }
    }

    public static int digitSum(String s) {
        int toReturn = 0;
        for (int i = 0; i < s.length(); i++) toReturn += Integer.parseInt(s.charAt(i) + " ");
        return toReturn;
    }

    public static boolean isPrime(long n) {
        if (n <= 1)
            return false;
        if (n <= 3)
            return true;

        if (n % 2 == 0 || n % 3 == 0)
            return false;

        for (long i = 5; i * i <= n; i = i + 6)
            if (n % i == 0 || n % (i + 2) == 0)
                return false;
        return true;
    }

    public static long pow(long a, long pow) {
        return pow == 0 ? 1 : pow % 2 == 0 ? pow(a * a, pow >> 1) : a * pow(a * a, pow >> 1);
    }

    public static long sumNum(long a) {
        return a * (a + 1) / 2;
    }

    public static int gcd(int n1, int n2) {
        return n2 == 0 ? n1 : gcd(n2, n1 % n2);
    }

    public static long factorial(long a) {
        return a == 0 || a == 1 ? 1 : a * factorial(a - 1);
    }

    public static void sort(int arr[]) {
        shuffle(arr);
        Arrays.sort(arr);
    }

    public static void shuffle(int arr[]) {
        Random rnd = new Random();
        for (int i = arr.length - 1; i > 0; i--) {
            int index = rnd.nextInt(i + 1);
            int temp = arr[index];
            arr[index] = arr[i];
            arr[i] = temp;
        }
    }

    public static Double[] solveQuadratic(double a, double b, double c) {
        double result = (b * b) - 4.0 * a * c;
        double r1;
        if (result > 0.0) {
            r1 = ((double) (-b) + Math.pow(result, 0.5)) / (2.0 * a);
            double r2 = ((double) (-b) - Math.pow(result, 0.5)) / (2.0 * a);
            return new Double[]{r1, r2};
        } else if (result == 0.0) {
            r1 = (double) (-b) / (2.0 * a);
            return new Double[]{r1, r1};
        } else {
            return new Double[]{null, null};
        }
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }

    static class pair<E1, E2> implements Comparable<pair> {
        E1 x;
        E2 y;

        pair(E1 x, E2 y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public int compareTo(pair o) {
            return x.equals(o.x) ? (Integer) y - (Integer) o.y : (Integer) x - (Integer) o.x;
        }

        @Override
        public String toString() {
            return x + " " + y;
        }

        public double pointDis(pair p1) {
            return Math.sqrt(((Integer) y - (Integer) p1.y) * ((Integer) y - (Integer) p1.y) + ((Integer) x - (Integer) p1.x) * ((Integer) x - (Integer) p1.x));
        }
    }

}


import java.io.*;
import java.util.*;
import java.math.*;

public class optimalCurrency {
    static Scanner sc = new Scanner(System.in);
    static PrintWriter pw = new PrintWriter(System.out), pw2 = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        int n=sc.nextInt(),d=sc.nextInt(),e=sc.nextInt();
        System.out.println(Math.min((n%d)%(5*e),(n%(5*e))%d));
    }

    public static <E> void print2D(E[][] arr) {
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                pw.println(arr[i][j]);
            }
        }
    }

    public static int digitSum(String s) {
        int toReturn = 0;
        for (int i = 0; i < s.length(); i++) toReturn += Integer.parseInt(s.charAt(i) + " ");
        return toReturn;
    }

    public static boolean isPrime(long n) {
        if (n <= 1)
            return false;
        if (n <= 3)
            return true;

        if (n % 2 == 0 || n % 3 == 0)
            return false;

        for (long i = 5; i * i <= n; i = i + 6)
            if (n % i == 0 || n % (i + 2) == 0)
                return false;
        return true;
    }

    public static long pow(long a, long pow) {
        return pow == 0 ? 1 : pow % 2 == 0 ? pow(a * a, pow >> 1) : a * pow(a * a, pow >> 1);
    }

    public static long sumNum(long a) {
        return a * (a + 1) / 2;
    }

    public static int gcd(int n1, int n2) {
        return n2 == 0 ? n1 : gcd(n2, n1 % n2);
    }

    public static long factorial(long a) {
        return a == 0 || a == 1 ? 1 : a * factorial(a - 1);
    }

    public static void sort(int arr[]) {
        shuffle(arr);
        Arrays.sort(arr);
    }

    public static void shuffle(int arr[]) {
        Random rnd = new Random();
        for (int i = arr.length - 1; i > 0; i--) {
            int index = rnd.nextInt(i + 1);
            int temp = arr[index];
            arr[index] = arr[i];
            arr[i] = temp;
        }
    }

    public static Double[] solveQuadratic(double a, double b, double c) {
        double result = (b * b) - 4.0 * a * c;
        double r1;
        if (result > 0.0) {
            r1 = ((double) (-b) + Math.pow(result, 0.5)) / (2.0 * a);
            double r2 = ((double) (-b) - Math.pow(result, 0.5)) / (2.0 * a);
            return new Double[]{r1, r2};
        } else if (result == 0.0) {
            r1 = (double) (-b) / (2.0 * a);
            return new Double[]{r1, r1};
        } else {
            return new Double[]{null, null};
        }
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }

    static class pair<E1, E2> implements Comparable<pair> {
        E1 x;
        E2 y;

        pair(E1 x, E2 y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public int compareTo(pair o) {
            return x.equals(o.x) ? (Integer) y - (Integer) o.y : (Integer) x - (Integer) o.x;
        }

        @Override
        public String toString() {
            return x + " " + y;
        }

        public double pointDis(pair p1) {
            return Math.sqrt(((Integer) y - (Integer) p1.y) * ((Integer) y - (Integer) p1.y) + ((Integer) x - (Integer) p1.x) * ((Integer) x - (Integer) p1.x));
        }
    }

}


import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main1 {
	static PrintWriter out = new PrintWriter(System.out);
	static FastReader input = new FastReader();

	public static void main(String[] args) throws IOException {
		long n, d, e;
		n = input.nextInt();
		d = input.nextInt();
		e = input.nextInt();

		long euro = 5 * e;
		long dollar = d;

		long min = Math.min((n % euro) % dollar, (n % dollar) % euro);
		out.println(min);
		out.flush();
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			// try {
			// br = new BufferedReader(new FileReader(new
			// File("C:/Users/Radwan/Desktop/coursera.txt")));
			// } catch (FileNotFoundException e) {
			// e.printStackTrace();
			// }
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreElements()) { st = new StringTokenizer(br.readLine()); }
			return st.nextToken();
		}

		int nextInt() throws NumberFormatException, IOException { return Integer.parseInt(next()); }

		long nextLong() throws NumberFormatException, IOException { return Long.parseLong(next()); }

		double nextDouble() throws NumberFormatException, IOException { return Double.parseDouble(next()); }

		String nextLine() throws IOException {
			String str = "";
			str = br.readLine();
			return str;
		}

		boolean hasNext() throws IOException { return br.ready(); }
	}

	static class Graph {
		ArrayList<Integer> g[];
		int n;

		Graph(int n) {
			this.n = n;
			g = new ArrayList[n];
			for (int i = 0; i < n; i++) { g[i] = new ArrayList<>(); }
		}

		void addEdge(int x, int y) {
			g[x].add(y);
			g[y].add(x);
		}

	}

	static class con {
		static int IINF = (int) 1e9;
		static int _IINF = (int) -1e9;
		static long LINF = (long) 1e15;
		static long _LINF = (long) -1e15;
		static double EPS = 1e-9;
	}

	static class Triple implements Comparable<Triple> {
		int x;
		int y;

		int z;

		Triple(int x, int y, int z) {
			this.x = x;
			this.y = y;
			this.z = z;
		}

		@Override
		public int compareTo(Triple o) {
			if (x == o.x && y == o.y)
				return z - o.z;
			if (x == o.x)
				return y - o.y;
			return x - o.x;
		}

		@Override
		public String toString() { return "(" + x + ", " + y + ", " + z + ")"; }
	}

	static class Pair implements Comparable<Pair> {
		int x;
		int y;

		Pair(int x, int y) {
			this.x = x;
			this.y = y;

		}

		@Override
		public int compareTo(Pair o) {
			if (x == o.x)
				return (int) (o.y - y);
			return (int) (o.x - x);
		}

		@Override
		public String toString() {

			return "(" + x + ", " + y + ")";
		}

	}

	static void shuffle(int[] a) {
		for (int i = 0; i < a.length; i++) {
			int r = i + (int) (Math.random() * (a.length - i));
			int tmp = a[r];
			a[r] = a[i];
			a[i] = tmp;
		}
	}

	static void shuffle(long[] a) {
		for (int i = 0; i < a.length; i++) {
			int r = i + (int) (Math.random() * (a.length - i));
			long tmp = a[r];
			a[r] = a[i];
			a[i] = tmp;
		}
	}

	static int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }

	static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); }

	static class DSU {

		int[] p, rank, setSize;
		int numSets;

		DSU(int n) {
			p = new int[n];
			rank = new int[n];
			setSize = new int[n];
			numSets = n;

			for (int i = 0; i < n; i++) {
				p[i] = i;
				setSize[i] = 1;
			}

		}

		int findSet(int n) { return p[n] = p[n] == n ? n : findSet(p[n]); }

		boolean isSameSet(int n, int m) { return findSet(n) == findSet(m); }

		void mergeSet(int n, int m) {

			if (!isSameSet(n, m)) {
				numSets--;
				int p1 = findSet(n);
				int p2 = findSet(m);

				if (rank[p1] > rank[p2]) {
					p[p2] = p1;
					setSize[p1] += setSize[p2];
				} else {
					p[p1] = p2;
					setSize[p2] += setSize[p1];
					if (rank[p1] == rank[p2])
						rank[p1]++;
				}
			}

		}

		int size() { return numSets; }

		int setSize(int n) { return setSize[findSet(n)]; }

	}

	static class Reader {
		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		public Reader() {
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public Reader(String file_name) throws IOException {
			din = new DataInputStream(new FileInputStream(file_name));
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public String readLine() throws IOException {
			byte[] buf = new byte[1024];
			int cnt = 0, c;
			while ((c = read()) != -1) {
				if (c == '\n')
					break;
				buf[cnt++] = (byte) c;
			}
			return new String(buf, 0, cnt);
		}

		public int nextInt() throws IOException {
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public long nextLong() throws IOException {
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public double nextDouble() throws IOException {
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9');
			if (c == '.')
				while ((c = read()) >= '0' && c <= '9')
					ret += (c - '0') / (div *= 10);
			if (neg)
				return -ret;
			return ret;
		}

		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		private byte read() throws IOException {
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		public void close() throws IOException {
			if (din == null)
				return;
			din.close();
		}
	}
}


import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main1 {
	static PrintWriter out = new PrintWriter(System.out);
	static FastReader input = new FastReader();
	static long n, d, e;

	public static void main(String[] args) throws IOException {

		n = input.nextInt();
		d = input.nextInt();
		e = input.nextInt();

		long dollar = d;
		long euro = e * 5;
		long min = n % dollar;

		for (int i = 1; i * euro <= n; i++) {
			long rem = n % (i * euro);
			min = Math.min(min, rem % dollar);
		}
		out.println(min);
		out.flush();
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			// try {
			// br = new BufferedReader(new FileReader(new
			// File("C:/Users/Radwan/Desktop/coursera.txt")));
			// } catch (FileNotFoundException e) {
			// e.printStackTrace();
			// }
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreElements()) { st = new StringTokenizer(br.readLine()); }
			return st.nextToken();
		}

		int nextInt() throws NumberFormatException, IOException { return Integer.parseInt(next()); }

		long nextLong() throws NumberFormatException, IOException { return Long.parseLong(next()); }

		double nextDouble() throws NumberFormatException, IOException { return Double.parseDouble(next()); }

		String nextLine() throws IOException {
			String str = "";
			str = br.readLine();
			return str;
		}

		boolean hasNext() throws IOException { return br.ready(); }
	}

	static class Graph {
		ArrayList<Integer> g[];
		int n;

		Graph(int n) {
			this.n = n;
			g = new ArrayList[n];
			for (int i = 0; i < n; i++) { g[i] = new ArrayList<>(); }
		}

		void addEdge(int x, int y) {
			g[x].add(y);
			g[y].add(x);
		}

	}

	static class con {
		static int IINF = (int) 1e9;
		static int _IINF = (int) -1e9;
		static long LINF = (long) 1e15;
		static long _LINF = (long) -1e15;
		static double EPS = 1e-9;
	}

	static class Triple implements Comparable<Triple> {
		int x;
		int y;

		int z;

		Triple(int x, int y, int z) {
			this.x = x;
			this.y = y;
			this.z = z;
		}

		@Override
		public int compareTo(Triple o) {
			if (x == o.x && y == o.y)
				return z - o.z;
			if (x == o.x)
				return y - o.y;
			return x - o.x;
		}

		@Override
		public String toString() { return "(" + x + ", " + y + ", " + z + ")"; }
	}

	static class Pair implements Comparable<Pair> {
		int x;
		int y;

		Pair(int x, int y) {
			this.x = x;
			this.y = y;

		}

		@Override
		public int compareTo(Pair o) {
			if (x == o.x)
				return (int) (o.y - y);
			return (int) (o.x - x);
		}

		@Override
		public String toString() {

			return "(" + x + ", " + y + ")";
		}

	}

	static void shuffle(int[] a) {
		for (int i = 0; i < a.length; i++) {
			int r = i + (int) (Math.random() * (a.length - i));
			int tmp = a[r];
			a[r] = a[i];
			a[i] = tmp;
		}
	}

	static void shuffle(long[] a) {
		for (int i = 0; i < a.length; i++) {
			int r = i + (int) (Math.random() * (a.length - i));
			long tmp = a[r];
			a[r] = a[i];
			a[i] = tmp;
		}
	}

	static int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }

	static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); }

	static class DSU {

		int[] p, rank, setSize;
		int numSets;

		DSU(int n) {
			p = new int[n];
			rank = new int[n];
			setSize = new int[n];
			numSets = n;

			for (int i = 0; i < n; i++) {
				p[i] = i;
				setSize[i] = 1;
			}

		}

		int findSet(int n) { return p[n] = p[n] == n ? n : findSet(p[n]); }

		boolean isSameSet(int n, int m) { return findSet(n) == findSet(m); }

		void mergeSet(int n, int m) {

			if (!isSameSet(n, m)) {
				numSets--;
				int p1 = findSet(n);
				int p2 = findSet(m);

				if (rank[p1] > rank[p2]) {
					p[p2] = p1;
					setSize[p1] += setSize[p2];
				} else {
					p[p1] = p2;
					setSize[p2] += setSize[p1];
					if (rank[p1] == rank[p2])
						rank[p1]++;
				}
			}

		}

		int size() { return numSets; }

		int setSize(int n) { return setSize[findSet(n)]; }

	}

	static class Reader {
		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		public Reader() {
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public Reader(String file_name) throws IOException {
			din = new DataInputStream(new FileInputStream(file_name));
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public String readLine() throws IOException {
			byte[] buf = new byte[1024];
			int cnt = 0, c;
			while ((c = read()) != -1) {
				if (c == '\n')
					break;
				buf[cnt++] = (byte) c;
			}
			return new String(buf, 0, cnt);
		}

		public int nextInt() throws IOException {
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public long nextLong() throws IOException {
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public double nextDouble() throws IOException {
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9');
			if (c == '.')
				while ((c = read()) >= '0' && c <= '9')
					ret += (c - '0') / (div *= 10);
			if (neg)
				return -ret;
			return ret;
		}

		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		private byte read() throws IOException {
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		public void close() throws IOException {
			if (din == null)
				return;
			din.close();
		}
	}
}


import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main1 {
	static PrintWriter out = new PrintWriter(System.out);
	static FastReader input = new FastReader();
	static long n, d, e;

	public static void main(String[] args) throws IOException {

		n = input.nextInt();
		d = input.nextInt();
		e = input.nextInt();

		long dollar = d;
		long euro = e * 5;
		long min = n;
		min = Math.min(min, min % euro);

		for (int i = 1; i * dollar <= n; i++) {
			long rem = n - (i * dollar);
			min = Math.min(min, rem % euro);
		}

		out.println(min);
		out.flush();
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			// try {
			// br = new BufferedReader(new FileReader(new
			// File("C:/Users/Radwan/Desktop/coursera.txt")));
			// } catch (FileNotFoundException e) {
			// e.printStackTrace();
			// }
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreElements()) { st = new StringTokenizer(br.readLine()); }
			return st.nextToken();
		}

		int nextInt() throws NumberFormatException, IOException { return Integer.parseInt(next()); }

		long nextLong() throws NumberFormatException, IOException { return Long.parseLong(next()); }

		double nextDouble() throws NumberFormatException, IOException { return Double.parseDouble(next()); }

		String nextLine() throws IOException {
			String str = "";
			str = br.readLine();
			return str;
		}

		boolean hasNext() throws IOException { return br.ready(); }
	}

	static class Graph {
		ArrayList<Integer> g[];
		int n;

		Graph(int n) {
			this.n = n;
			g = new ArrayList[n];
			for (int i = 0; i < n; i++) { g[i] = new ArrayList<>(); }
		}

		void addEdge(int x, int y) {
			g[x].add(y);
			g[y].add(x);
		}

	}

	static class con {
		static int IINF = (int) 1e9;
		static int _IINF = (int) -1e9;
		static long LINF = (long) 1e15;
		static long _LINF = (long) -1e15;
		static double EPS = 1e-9;
	}

	static class Triple implements Comparable<Triple> {
		int x;
		int y;

		int z;

		Triple(int x, int y, int z) {
			this.x = x;
			this.y = y;
			this.z = z;
		}

		@Override
		public int compareTo(Triple o) {
			if (x == o.x && y == o.y)
				return z - o.z;
			if (x == o.x)
				return y - o.y;
			return x - o.x;
		}

		@Override
		public String toString() { return "(" + x + ", " + y + ", " + z + ")"; }
	}

	static class Pair implements Comparable<Pair> {
		int x;
		int y;

		Pair(int x, int y) {
			this.x = x;
			this.y = y;

		}

		@Override
		public int compareTo(Pair o) {
			if (x == o.x)
				return (int) (o.y - y);
			return (int) (o.x - x);
		}

		@Override
		public String toString() {

			return "(" + x + ", " + y + ")";
		}

	}

	static void shuffle(int[] a) {
		for (int i = 0; i < a.length; i++) {
			int r = i + (int) (Math.random() * (a.length - i));
			int tmp = a[r];
			a[r] = a[i];
			a[i] = tmp;
		}
	}

	static void shuffle(long[] a) {
		for (int i = 0; i < a.length; i++) {
			int r = i + (int) (Math.random() * (a.length - i));
			long tmp = a[r];
			a[r] = a[i];
			a[i] = tmp;
		}
	}

	static int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }

	static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); }

	static class DSU {

		int[] p, rank, setSize;
		int numSets;

		DSU(int n) {
			p = new int[n];
			rank = new int[n];
			setSize = new int[n];
			numSets = n;

			for (int i = 0; i < n; i++) {
				p[i] = i;
				setSize[i] = 1;
			}

		}

		int findSet(int n) { return p[n] = p[n] == n ? n : findSet(p[n]); }

		boolean isSameSet(int n, int m) { return findSet(n) == findSet(m); }

		void mergeSet(int n, int m) {

			if (!isSameSet(n, m)) {
				numSets--;
				int p1 = findSet(n);
				int p2 = findSet(m);

				if (rank[p1] > rank[p2]) {
					p[p2] = p1;
					setSize[p1] += setSize[p2];
				} else {
					p[p1] = p2;
					setSize[p2] += setSize[p1];
					if (rank[p1] == rank[p2])
						rank[p1]++;
				}
			}

		}

		int size() { return numSets; }

		int setSize(int n) { return setSize[findSet(n)]; }

	}

	static class Reader {
		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		public Reader() {
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public Reader(String file_name) throws IOException {
			din = new DataInputStream(new FileInputStream(file_name));
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public String readLine() throws IOException {
			byte[] buf = new byte[1024];
			int cnt = 0, c;
			while ((c = read()) != -1) {
				if (c == '\n')
					break;
				buf[cnt++] = (byte) c;
			}
			return new String(buf, 0, cnt);
		}

		public int nextInt() throws IOException {
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public long nextLong() throws IOException {
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public double nextDouble() throws IOException {
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9');
			if (c == '.')
				while ((c = read()) >= '0' && c <= '9')
					ret += (c - '0') / (div *= 10);
			if (neg)
				return -ret;
			return ret;
		}

		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		private byte read() throws IOException {
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		public void close() throws IOException {
			if (din == null)
				return;
			din.close();
		}
	}
}


import java.util.*;

public class Main
{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		long n=sc.nextLong();
		long a=sc.nextInt();
		long b=5*(sc.nextInt());
		long tmp=0,min=Long.MAX_VALUE;
		while(tmp<=n)
		{
		  long val=a*((n-tmp)/a);
		  min=Math.min(min,n-val-tmp);
		  tmp+=b;
		}
		System.out.println(min);
	}
}


import java.util.*;

public class Main
{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		long n=sc.nextLong();
		long a=sc.nextInt();
		long b=5*(sc.nextInt());
		long tmp=0,min=Long.MAX_VALUE;
		while(tmp<n)
		{
		  long val=a*((n-tmp)/a);
		  min=Math.min(min,n-val-tmp);
		  tmp+=b;
		}
		System.out.println(min);
	}
}


import java.util.*;

public class CF_1214A {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt(),d=sc.nextInt(),e=sc.nextInt();
		int n1=n/d;
		int ans=n-n1*d,sum=n1*d;
		for(int i=n1-1;i>=1;i--) {
			ans=Math.min(ans, (n-i*d)%(5*e));
//			System.out.println("-----");
		}
		System.out.print(ans);
	}
}


import java.util.*;

public class CF_1214A {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt(),d=sc.nextInt(),e=sc.nextInt();
		int n1=n/d;
		int ans=n-n1*d,sum=n1*d;
//		System.out.println("-----"+ans+" "+sum+" "+n1);
		for(int i=n1-1;i>=0;i--) {
			ans=Math.min(ans, (n-i*d)%(5*e));
//			System.out.println("-----"+" "+(n-i*d)%(5*e)+" "+i);
		}
		System.out.print(ans);
	}
}


import java.util.Scanner;

public class CF_1214A{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt(),d=sc.nextInt(),e=sc.nextInt();
        int dval=d,eval=5*e;
        int n1=n/dval,n2=n/eval;
        int ans=Integer.MAX_VALUE;
        int sum=0;
        for(int i=0;i<=n1;i++){
                // System.out.println(i+"-----"+n+"----"+sum+"----"+n2);
            for(int j=0;j<=n2;j++){
                // System.out.println(i+"-----"+j+"-----"+ans);
                sum=i*dval+j*eval;
                if(sum<=n){
                    ans=Math.min(ans,n-sum);
                }
                else break;
            }
        }
        System.out.println(ans);
    }
}


import java.util.*;

public class CF_1214A {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt(),d=sc.nextInt(),e=sc.nextInt();
		int r1=n%(5*e);int r2=r1%d;
		int R1=n%d;int R2=R1%(5*e);
		System.out.println(Math.min(R2, r2));
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class ProblemA {
	public static void main(String[] args) throws IOException {
		InputStream in = System.in;
		InputReader scan = new InputReader(in);
		int n = scan.nextInt();
		int d = scan.nextInt();
		int e = scan.nextInt();
		int e5 = e*5;
		int res = n;
		for(int i=0;i*e5<=n;i++) {
			int curr = (n-(i*e5))%d;
			res = Math.min(res, curr);
		}
		System.out.println(res);
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class ProblemA {
	public static void main(String[] args) throws IOException {
		InputStream in = System.in;
		InputReader scan = new InputReader(in);
		int n = scan.nextInt();
		int d = scan.nextInt();
		int e = scan.nextInt();
		int e5 = e*5;
		int res1= (n%d)%e5;
		int res2 = (n%e5)%d;
		int res = Math.min(res1, res2);
		System.out.println(res);
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


import java.io.*;
import java.util.StringTokenizer;

import static java.lang.Long.min;
import static java.lang.Math.max;

public class Problem1214A {

    private static PrintWriter out;

    static {
        try {
            out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out, "UTF-8"), 512));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws IOException {
        final BufferedReader bufferReader = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer stringTokenizer;

        stringTokenizer = new StringTokenizer(bufferReader.readLine());
        long n = Long.parseLong(stringTokenizer.nextToken());
        stringTokenizer = new StringTokenizer(bufferReader.readLine());
        long d = Long.parseLong(stringTokenizer.nextToken());
        stringTokenizer = new StringTokenizer(bufferReader.readLine());
        long e = Long.parseLong(stringTokenizer.nextToken());
        out.println(getResult(n, e, d));

        out.flush();
    }

    private static long getResultFor(long n, long e, long d, long dollars) {
        long dollarsRub = dollars * d;
        long remainingForEuro = n - dollarsRub;
        long euro = remainingForEuro / (5 * e);

        return n - dollarsRub - (euro * e * 5);
    }

    private static long getResult(long n, long e, long d) {
        long minRemainder = Long.MAX_VALUE;
        long maxDollars = n / d;

        for (int i = 0; i <= maxDollars; ++i) {
            long result = getResultFor(n, e, d, i);
            minRemainder = min(minRemainder, result);
        }

        if (minRemainder == Long.MAX_VALUE) {
            return 0;
        }

        return minRemainder;
    }
}


import java.io.*;
import java.util.StringTokenizer;

import static java.lang.Math.max;

public class Problem1214A {

    private static PrintWriter out;

    static {
        try {
            out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out, "UTF-8"), 512));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws IOException {
        final BufferedReader bufferReader = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer stringTokenizer;

        stringTokenizer = new StringTokenizer(bufferReader.readLine());
        long n = Long.parseLong(stringTokenizer.nextToken());
        stringTokenizer = new StringTokenizer(bufferReader.readLine());
        long d = Long.parseLong(stringTokenizer.nextToken());
        stringTokenizer = new StringTokenizer(bufferReader.readLine());
        long e = Long.parseLong(stringTokenizer.nextToken());
        out.println(getResult(n, e, d));

        out.flush();
    }

    private static long getResult(long n, long e, long d) {
        long firstPart = (n / (5 * e));
        long first = firstPart + ((n - firstPart) / d) * d;
        long second = n / d * d;

        long max = max(first, second);
        return n - max;
    }
}


import java.util.*;
import java.io.*;
import java.math.*;
public class Main{
	static int mod = (int)1e9+7;
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	public static void main(String sp[])throws IOException{
		FastReader sc = new FastReader();

		long n = sc.nextLong();
		long d = sc.nextLong();
		long e = sc.nextLong();
		ArrayList<Long> al1 = new ArrayList<>();
		al1.add(1*d);

		ArrayList<Long> al2 = new ArrayList<>();
		al2.add(5*e);
		long h=n;
		while(n/al1.get(0)>0){
			n=n%al1.get(0);
		}
		while(n/al2.get(0)>0){
			n=n%al2.get(0);
		}
		while(h/al2.get(0)>0){
			h=h%al2.get(0);
		}
		while(h/al1.get(0)>0){
			h=h%al1.get(0);
		}
		System.out.println(Math.min(n,h));
		out.close();
	}

	public static int partition(int [] arr, int s, int e){

		int index=s;
		int pivot = arr[e];
		for(int i=s;i<=e-1;i++){
			if(arr[i]<=pivot){
				arr = swap(arr, index, i);
				index++;
			}
		}
		swap(arr,index,e);
		print(arr);
		return index;
	}

	public static int[] swap(int[] arr, int low, int high){
		int temp = arr[low];
		arr[low]=arr[high];
		arr[high]=temp;
		return arr;
	}

	public static long gcd(long a, long b){
		if(a==0)
			return b;

		return gcd(b%a,a);
	}

	public static void print(int[] arr){
		for(int i=0;i<arr.length;i++)
			System.out.print(arr[i]+" ");
		System.out.println();
	}

	public static class pair{
		int ai;
		int bi;
	}

	public static class comp implements Comparator<pair>{
		public int compare(pair o1, pair o2){
			return o1.bi-o2.bi;
		}
	}
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}

}


import java.util.*;
import java.io.*;
import java.math.*;
public class Main{
	static int mod = (int)1e9+7;
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	public static void main(String sp[])throws IOException{
		FastReader sc = new FastReader();

		long n = sc.nextLong();
		long d = sc.nextLong();
		long e = sc.nextLong();

		long total1 = 1*d;
		long total2 = 5*e;
		long min = Long.MAX_VALUE;
		for(int j=0;;j++){
			long calc = total1*j;
			if(calc>n)
				break;
			long temp = n;
			if(calc==0)
				temp=n;
			else temp-=calc;
			temp = temp%total2;
			min = Math.min(min,temp);
		}
		System.out.println(min);
		out.close();
	}

	public static int partition(int [] arr, int s, int e){

		int index=s;
		int pivot = arr[e];
		for(int i=s;i<=e-1;i++){
			if(arr[i]<=pivot){
				arr = swap(arr, index, i);
				index++;
			}
		}
		swap(arr,index,e);
		print(arr);
		return index;
	}

	public static int[] swap(int[] arr, int low, int high){
		int temp = arr[low];
		arr[low]=arr[high];
		arr[high]=temp;
		return arr;
	}

	public static long gcd(long a, long b){
		if(a==0)
			return b;

		return gcd(b%a,a);
	}

	public static void print(int[] arr){
		for(int i=0;i<arr.length;i++)
			System.out.print(arr[i]+" ");
		System.out.println();
	}

	public static class pair{
		int ai;
		int bi;
	}

	public static class comp implements Comparator<pair>{
		public int compare(pair o1, pair o2){
			return o1.bi-o2.bi;
		}
	}
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}

}


import java.util.*;
import java.io.*;
import java.math.*;
public class Main{
	static int mod = (int)1e9+7;
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	public static void main(String sp[])throws IOException{
		FastReader sc = new FastReader();

		long n = sc.nextLong();
		long d = sc.nextLong();
		long e = sc.nextLong();
		ArrayList<Long> al1 = new ArrayList<>();
		al1.add(1*d);
		al1.add(2*d);
		al1.add(5*d);
		al1.add(10*d);
		al1.add(20*d);
		al1.add(50*d);
		al1.add(100*d);

		al1.add(5*e);
		al1.add(10*e);
		al1.add(20*e);
		al1.add(50*e);
		al1.add(100*e);
		al1.add(200*e);
		Collections.sort(al1,Collections.reverseOrder());
		for(int i=0;i<al1.size();i++){
			n=n%al1.get(i);
		}
		System.out.println(n);
		out.close();
	}

	public static int partition(int [] arr, int s, int e){

		int index=s;
		int pivot = arr[e];
		for(int i=s;i<=e-1;i++){
			if(arr[i]<=pivot){
				arr = swap(arr, index, i);
				index++;
			}
		}
		swap(arr,index,e);
		print(arr);
		return index;
	}

	public static int[] swap(int[] arr, int low, int high){
		int temp = arr[low];
		arr[low]=arr[high];
		arr[high]=temp;
		return arr;
	}

	public static long gcd(long a, long b){
		if(a==0)
			return b;

		return gcd(b%a,a);
	}

	public static void print(int[] arr){
		for(int i=0;i<arr.length;i++)
			System.out.print(arr[i]+" ");
		System.out.println();
	}

	public static class pair{
		int ai;
		int bi;
	}

	public static class comp implements Comparator<pair>{
		public int compare(pair o1, pair o2){
			return o1.bi-o2.bi;
		}
	}
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}

}


import java.util.*;
import java.io.*;
import java.math.*;
public class Main{
	static int mod = (int)1e9+7;
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	public static void main(String sp[])throws IOException{
		FastReader sc = new FastReader();

		long n = sc.nextLong();
		long d = sc.nextLong();
		long e = sc.nextLong();
		ArrayList<Long> al1 = new ArrayList<>();
		al1.add(1*d);
		al1.add(2*d);
		al1.add(5*d);
		al1.add(10*d);
		al1.add(20*d);
		al1.add(50*d);
		al1.add(100*d);

		al1.add(5*e);
		al1.add(10*e);
		al1.add(20*e);
		al1.add(50*e);
		al1.add(100*e);
		al1.add(200*e);
		long h=n;
		Collections.sort(al1,Collections.reverseOrder());
		for(int i=0;i<al1.size();i++){
			n=n%al1.get(i);
		}
		Collections.sort(al1);
		for(int i=0;i<al1.size();i++){
			h=h%al1.get(i);
		}
		System.out.println(Math.min(n,h));
		out.close();
	}

	public static int partition(int [] arr, int s, int e){

		int index=s;
		int pivot = arr[e];
		for(int i=s;i<=e-1;i++){
			if(arr[i]<=pivot){
				arr = swap(arr, index, i);
				index++;
			}
		}
		swap(arr,index,e);
		print(arr);
		return index;
	}

	public static int[] swap(int[] arr, int low, int high){
		int temp = arr[low];
		arr[low]=arr[high];
		arr[high]=temp;
		return arr;
	}

	public static long gcd(long a, long b){
		if(a==0)
			return b;

		return gcd(b%a,a);
	}

	public static void print(int[] arr){
		for(int i=0;i<arr.length;i++)
			System.out.print(arr[i]+" ");
		System.out.println();
	}

	public static class pair{
		int ai;
		int bi;
	}

	public static class comp implements Comparator<pair>{
		public int compare(pair o1, pair o2){
			return o1.bi-o2.bi;
		}
	}
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}

}


import java.util.*;
import java.io.*;
import java.math.*;
public class OptimalCurrencyExchange
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine());
        int d=Integer.parseInt(br.readLine());
        int e=Integer.parseInt(br.readLine());
        int ans = n;
        for (int i = 0; i * 5 * e <= n; ++i)
        {
            ans = Math.min(ans, (n - i * 5 * e) % d);
        }
        System.out.println(ans);
    }
}


import java.util.*;
import java.io.*;
public class OptimalCurrencyExchange
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine());
        int d=Integer.parseInt(br.readLine());
        int e=Integer.parseInt(br.readLine());
        int ans = n;
        for (int i = 0; i * 5 * e <= n; ++i)
        {
            ans = min(ans, (n - i * 5 * e) % d);
        }
        System.out.println(ans);
    }
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class Main {

	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}

	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
    //public static long mod = (long) (1e9+7);
    public final static int MAX = (int)1e5;
  // static Scanner sc = new Scanner(System.in);
   static List<Integer>[] edge;
   private static int N = (int) (2e5 + 11);
	public static void main(String[] args) {

	 FastReader sc = new FastReader();

     long n = sc.nextLong();
     long d = sc.nextLong();
     long e = sc.nextLong();
     int[] D = {0, 1 , 2, 5, 10, 20, 50, 100 };
     int[] E = {0, 5 , 10, 20, 50, 100, 200 };
     long min = n;
     min = Math.min(min,solve(D,E,d,e,n));
     out.println(min);
	 out.close();
	}
	private static long solve(int[] D, int[] E, long d, long e, long n) {
		long min = n;
		 for(int i=0;i<D.length;++i) {
	    	 for(int j=0;j<E.length;++j) {
	    		 long ans = d*D[i] + e*E[j];
	    		 if(ans <= n) min = Math.min(min, n-ans);
	    	 }
	     }
		return min;
	}

}


//package practice;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
import java.util.Stack;

public class Main {

	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}

	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
    //public static long mod = (long) (1e9+7);
    public final static int MAX = (int)1e5;
  // static Scanner sc = new Scanner(System.in);
   static List<Integer>[] edge;
   private static int N = (int) (2e5 + 11);
	public static void main(String[] args) {

	 FastReader sc = new FastReader();

	 long n = sc.nextLong();
	 long D = sc.nextLong();
	 long E = sc.nextLong();
	 long d = D,e = 5*E;
	 boolean run = true;
	 long k = 0;
	 long min = n;
	 while(k*d <= n) {

		 min = Math.min(min,(n-k*d)%e);
		 ++k;
	 }
	 d = D;
	 k = 0;
	 while(k*e <= n) {

		 min = Math.min(min,(n-k*e)%d);
		 ++k;
	 }

	 out.print(min);
	 out.close();
	}

}


//package practice;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class Main {

	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}

	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
    //public static long mod = (long) (1e9+7);
    public final static int MAX = (int)1e5;
  // static Scanner sc = new Scanner(System.in);
   static List<Integer>[] edge;
   private static int N = (int) (2e5 + 11);
	public static void main(String[] args) {

	 FastReader sc = new FastReader();

     long n = sc.nextLong();
     long d = sc.nextLong();
     long e = sc.nextLong();
     int[] D = {0, 1 , 2, 5, 10, 20, 50, 100 };
     int[] E = {0, 5 , 10, 20, 50, 100, 200 };
     long min = n;
     min = Math.min(min,Math.min(solve(D,E,d,e,n),solve(E,D,e,d,n)));
     out.println(min);
	 out.close();
	}
	private static long solve(int[] D, int[] E, long d, long e, long n) {
		long min = n;
		 for(int i=0;i<D.length;++i) {
	    	 if(d*D[i] <= n) {
	    		 long N = n - d*D[i];
	    	 for(int j=0;j<E.length;++j) {
	    		 if(e*E[j] <= N) {
	    			 min = Math.min(min,N-e*E[j]);
	    		 }else break;
	    	 }
	       }else break;
	     }
		return min;
	}

}