#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define R(i,b,a) for(int i=(int)(b);i>=(int)(a);i--)
#define endl "\n"
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define out(x) cout<<setprecision(15)<<x<<endl,exit(0)
#define pii pair<int,int>
#define pb push_back
#define all(v) v.begin(),v.end()
#define I first
#define S second
#define ld long double
ld pi=3.14159265359;

const int N=1002;
int arr[N];

int32_t main(){
	int n,m,c;
	cin>>n>>m>>c;

	multiset <int> cl;
	multiset <int,greater<int> > cr;
	cl.insert(1);
	cr.insert(c);

	F(i,1,m){
		int x,pos;
		cin>>x;

		int a=*cl.rbegin();
		int b=*cr.rbegin();
		if(a<=x && b>=x){
			if(abs(a-x)<=abs(b-x)) pos=cl.size(),cl.insert(x);
			else pos=n-cr.size()+1,cr.insert(x);
			arr[x]=pos;
		}
		else if(x<a){
			int tmp=*cl.lower_bound(x+1);
			pos=arr[tmp];
			cl.insert(x);
			cl.erase(cl.find(tmp));
			if(arr[x]) arr[x]=min(arr[x],pos);
			else arr[x]=pos;
		}
		else{
			int tmp=*cr.lower_bound(x-1);
			pos=arr[tmp];
			cr.insert(x);
			cr.erase(cr.find(tmp));
			arr[x]=max(arr[x],pos);
		}

		cout<<pos<<endl;
		if(cl.size()+cr.size()==n+2) exit(0);
	}
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define R(i,b,a) for(int i=(int)(b);i>=(int)(a);i--)
#define endl "\n"
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define out(x) cout<<setprecision(15)<<x<<endl,exit(0)
#define pii pair<int,int>
#define pb push_back
#define all(v) v.begin(),v.end()
#define I first
#define S second
#define ld long double
ld pi=3.14159265359;

const int N=1002;
int arr[N];

int32_t main(){
	int n,m,c;
	cin>>n>>m>>c;

	multiset <int> cl;
	multiset <int,greater<int> > cr;
	cl.insert(1);
	cr.insert(c);

	F(i,1,m){
		int x,pos;
		cin>>x;

		int a=*cl.rbegin();
		int b=*cr.rbegin();
		if(a<=x && b>=x){
			if(abs(a-x)<=abs(b-x)) pos=cl.size(),cl.insert(x);
			else pos=n-cr.size()+1,cr.insert(x);
		}
		else if(x<a){
			int tmp=*cl.lower_bound(x+1);
			pos=arr[tmp];
			cl.insert(x);
			cl.erase(cl.find(tmp));
		}
		else{
			int tmp=*cr.lower_bound(x-1);
			pos=arr[tmp];
			cr.insert(x);
			cr.erase(cr.find(tmp));
		}

		arr[x]=pos;
		cout<<pos<<endl;
		if(cl.size()+cr.size()==n+2) exit(0);
	}
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define R(i,b,a) for(int i=(int)(b);i>=(int)(a);i--)
#define endl "\n"
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define out(x) cout<<setprecision(15)<<x<<endl,exit(0)
#define pii pair<int,int>
#define pb push_back
#define all(v) v.begin(),v.end()
#define I first
#define S second
#define ld long double
ld pi=3.14159265359;

const int N=1002;
int arr[N];

int32_t main(){
	int n,m,c;
	cin>>n>>m>>c;

	vector <int> cl={1},cr={c};

	F(j,1,m){
		int x,pos;
		cin>>x;

		int a=cl.back();
		int b=cr.back();

		if(a<=x && b>=x){
			if(abs(a-x)<=abs(b-x)) pos=cl.size(),cl.pb(x);
			else pos=n-cr.size()+1,cr.pb(x);
		}
		else if(x<a){
			F(i,0,cl.size()-1){
				if(cl[i]>x){
					cl.erase(cl.begin()+i);
					cl.insert(cl.begin()+i,x);
					pos=i;
					break;
				}
			}
		}
		else{
			F(i,0,cr.size()-1){
				if(cr[i]<x){
					cr.erase(cr.begin()+i);
					cr.insert(cr.begin()+i,x);
					pos=n-i+1;
					break;
				}
			}
		}
		cout<<pos<<endl;
		if(cl.size()+cr.size()==n+2) exit(0);
	}
}


/*input
3 6 3
1
2
1
3
1
3
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
	ll n, m, c;
	cin >> n >> m >> c;
	ll a[n + 2];
	ll b[n + 2];
	fill_n(a, n + 2, (ll)1e6);
	fill_n(b, n + 2, -2);
	ll x;
	while (cin >> x)
	{
		int i1 = 1;
		int i2 = n;
		while (a[i1] <= x)
			i1++;
		while (b[i2] >= x)
			i2--;
		int i = i2;
		if (x * 2 <= c)
		{
			i = i1;
		}
		else
		{
			i = i2;
		}
		if (i2 < n / 2)
			i = i2;
		if (i1 > n / 2)
			i = i1;
		cout << i << endl;
		for (ll j = i; j >= 0; j--)
			b[j] = -2;
		for (ll j = i; j < n + 2; j++)
			a[j] = 1e6;
		a[i] = x;
		b[i] = x;
	}
}


/*input
3 6 3
1
2
1
3
1
3
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
	ll n, m, c;
	cin >> n >> m >> c;
	ll a[n + 2];
	ll b[n + 2];
	fill_n(a, n + 2, n + 5);
	fill_n(b, n + 2, -2);
	ll x;
	while (cin >> x)
	{
		int i;
		if (x * 2 <= c)
		{
			i = 1;
			while (a[i] <= x)
				i++;
		}
		else
		{
			i = n;
			while (b[i] >= x)
				i--;
		}
		cout << i << endl;
		for (ll j = i; j >= 0; j--)
			b[j] = -2;
		for (ll j = i; j < n + 2; j++)
			a[j] = n + 5;
		a[i] = x;
		b[i] = x;
	}
}


/*input
2 4 4
2
1
3
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
	ll n, m, c;
	cin >> n >> m >> c;
	ll a[n + 2];
	ll b[n + 2];
	fill_n(a, n + 2, n + 5);
	fill_n(b, n + 2, -2);
	ll x;
	while (cin >> x)
	{
		int i;
		if (x * 2 < c)
		{
			i = 1;
			while (a[i] <= x)
				i++;
		}
		else
		{
			i = n;
			while (b[i] >= x)
				i--;
		}
		cout << i << endl;
		for (ll j = i; j >= 0; j--)
			b[j] = -2;
		for (ll j = i; j < n + 2; j++)
			a[j] = -2;
		a[i] = x;
		b[i] = x;
	}
}


/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
         static class Input {
        private StringTokenizer tokenizer = null;
        private BufferedReader reader;

        public Input(InputStream inputStream) {
            reader = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(nextLine());
            }
            return tokenizer.nextToken();
        }

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

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

        public int[] nextIntArray(int n, int add) {
            int[] result = new int[n];
            for (int i = 0; i < n; i++) {
                result[i] = nextInt() + add;
            }
            return result;
        }

        public long[] nextLongArray(int n, long add) {
            long[] result = new long[n];
            for (int i = 0; i < n; i++) {
                result[i] = nextLong() + add;
            }
            return result;
        }

        public int[] nextIntArray(int n) {
            return nextIntArray(n, 0);
        }

    }

	public static void main (String[] args) throws java.lang.Exception
	{
		Input s=new Input(System.in);
		int t=1;
		PrintWriter out=new PrintWriter(System.out);

		while(t-->0)
		{
		    int n=s.nextInt();
		    int ba=s.nextInt();
		    int e=s.nextInt();
		    int a[]=new int[]{5,10,20,50,100,200};
		    int b[]=new int[]{1,2,5,10,20,50,100,500};
		    ArrayList<Integer> ar1=new ArrayList<>();
		    ar1.add(0);
		    int sum=0;
		    for(int i=0;i<6;i++)
		    {
		        for(int j=a[i];j<=a[i]+sum;j++)
		            ar1.add(j);

		    }

		    ArrayList<Integer> ar2=new ArrayList<>();
		    ar2.add(0);
		    sum=0;
		    for(int i=0;i<8;i++)
		    {
		        for(int j=b[i];j<=b[i]+sum;j++)
		            ar2.add(j);

		    }

		    int min=n;
		    for(Integer i:ar1)
	            for(Integer j:ar2)
	              if(i*e+j*ba<=n)
	              min=Math.min(n-i*e-j*ba,min);

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


/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
         static class Input {
        private StringTokenizer tokenizer = null;
        private BufferedReader reader;

        public Input(InputStream inputStream) {
            reader = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(nextLine());
            }
            return tokenizer.nextToken();
        }

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

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

        public int[] nextIntArray(int n, int add) {
            int[] result = new int[n];
            for (int i = 0; i < n; i++) {
                result[i] = nextInt() + add;
            }
            return result;
        }

        public long[] nextLongArray(int n, long add) {
            long[] result = new long[n];
            for (int i = 0; i < n; i++) {
                result[i] = nextLong() + add;
            }
            return result;
        }

        public int[] nextIntArray(int n) {
            return nextIntArray(n, 0);
        }

    }

	public static void main (String[] args) throws java.lang.Exception
	{
		Input s=new Input(System.in);
		int t=1;
		PrintWriter out=new PrintWriter(System.out);

		while(t-->0)
		{
		    int n=s.nextInt();
		    int ba=s.nextInt();
		    int e=s.nextInt();
		    int a[]=new int[]{5,10,20,50,100,200};
		    int b[]=new int[]{1,2,5,10,20,50,100,500};
		    ArrayList<Integer> ar1=new ArrayList<>();
		    ar1.add(0);
		    int sum=0;
		    for(int i=0;i<6;i++)
		    {
		        for(int j=a[i];j<=a[i]+sum;j+=5)
		         {   ar1.add(j);

		         }
		       sum+=a[i];
		    }

		    //System.out.println(ar1);

		    ArrayList<Integer> ar2=new ArrayList<>();
		    ar2.add(0);
		    sum=0;
		    for(int i=0;i<8;i++)
		    {
		        for(int j=b[i];j<=b[i]+sum;j++)
		            ar2.add(j);
		        sum+=b[i];
		    }

		    int min=n;
		    for(Integer i:ar1)
	            for(Integer j:ar2)
	              if(i*e+j*ba<=n)
	              min=Math.min(n-i*e-j*ba,min);

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


/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
         static class Input {
        private StringTokenizer tokenizer = null;
        private BufferedReader reader;

        public Input(InputStream inputStream) {
            reader = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(nextLine());
            }
            return tokenizer.nextToken();
        }

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

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

        public int[] nextIntArray(int n, int add) {
            int[] result = new int[n];
            for (int i = 0; i < n; i++) {
                result[i] = nextInt() + add;
            }
            return result;
        }

        public long[] nextLongArray(int n, long add) {
            long[] result = new long[n];
            for (int i = 0; i < n; i++) {
                result[i] = nextLong() + add;
            }
            return result;
        }

        public int[] nextIntArray(int n) {
            return nextIntArray(n, 0);
        }

    }

	public static void main (String[] args) throws java.lang.Exception
	{
		Input s=new Input(System.in);
		int t=1;
		PrintWriter out=new PrintWriter(System.out);

		while(t-->0)
		{
		    int n=s.nextInt();
		    int ba=s.nextInt();
		    int e=s.nextInt()*5;
		    int min=n;
		    for(int i=0;i<=n/ba;i++)
		        min=Math.min((n-i*ba)%e,min);

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


import java.util.Scanner;

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

    }

}


import java.util.Scanner;

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

    }

}


import java.util.Scanner;

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

    }

}


								//package Dynamic;
import java.io.*;
import java.util.*;
public class Main{
	static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer st;
    static public void main(String[] args)throws IOException{
    	st=new StringTokenizer(br.readLine());
    	int n=i();
    	int d=i();
    	int e=5*i();
    	int x=Math.max(d,e);
    	int y=Math.min(d,e);
    	int min=Integer.MAX_VALUE;
    	int val=n;
    	//n-=x;
    	while(n>=0)
    	{

    		min=Math.min(min,n%y);
    		if(min==0)
    			{
    			pl(0);
    				System.exit(0);
    			}
    		n-=x;
    	}
    	n=val;
    	//n-=y;
    	//pl(min);
    	while(n>=0)
    	{

    		min=Math.min(min,n%x);
    		//pl(n+" "+min);
    		if(min==0){
    			pl(0);
				System.exit(0);
			}
    		n-=y;
    	}

    	pl(min);
    }
    static int i()throws IOException
    {
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	return Integer.parseInt(st.nextToken());
    }
    static long l()throws IOException
    {
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	return Long.parseLong(st.nextToken());
    }
    static String s()throws IOException
    {
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	return st.nextToken();
    }
    static double d()throws IOException
    {
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	return Double.parseDouble(st.nextToken());
    }
    static void p(String p)
    {
    	System.out.print(p);
    }
    static void p(int p)
    {
    	System.out.print(p);
    }
    static void p(double p)
    {
    	System.out.print(p);
    }
    static void p(long p)
    {
    	System.out.print(p);
    }
    static void p(char p)
    {
    	System.out.print(p);
    }
    static void p(boolean p)
    {
    	System.out.print(p);
    }
    static void pl(String pl)
    {
    	System.out.println(pl);
    }
    static void pl(int pl)
    {
    	System.out.println(pl);
    }
    static void pl(char pl)
    {
    	System.out.println(pl);
    }
    static void pl(double pl)
    {
    	System.out.println(pl);
    }
    static void pl(long pl)
    {
    	System.out.println(pl);
    }
    static void pl(boolean pl)
    {
    	System.out.println(pl);
    }
    static void pl()
    {
    	System.out.println();
    }
    static int[] ari(int n)throws IOException
    {
    	int ar[]=new int[n];
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	for(int x=0;x<n;x++)
    		ar[x]=i();
    	return ar;
    }
    static long[] arl(int n)throws IOException
    {
    	long ar[]=new long[n];
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	for(int x=0;x<n;x++)
    		ar[x]=l();
    	return ar;
    }
    static String[] ars(int n)throws IOException
    {
    	String ar[]=new String[n];
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	for(int x=0;x<n;x++)
    		ar[x]=s();
    	return ar;
    }
    static double[] ard(int n)throws IOException
    {
    	double ar[]=new double[n];
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	for(int x=0;x<n;x++)
    		ar[x]=d();
    	return ar;
    }
    static char[] arc(int n)throws IOException
    {
    	char ar[]=new char[n];
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	for(int x=0;x<n;x++)
    		ar[x]=st.nextToken().charAt(0);
    	return ar;
    }
    static void pari(int ar[])
    {
    	for(int a:ar)
    		System.out.print(a+" ");
    }
    static void parl(long ar[])
    {
    	for(long a:ar)
    		System.out.print(a+" ");
    }
    static void pars(String ar[])
    {
    	for(String a:ar)
    		System.out.print(a+" ");
    }
    static void pard(double ar[])
    {
    	for(double a:ar)
    		System.out.print(a+" ");
    }
    static void parc(char ar[])
    {
    	for(char a:ar)
    		System.out.print(a+" ");
    }
}
class ar implements Comparable<ar>
{
	int ar[]=new int[2];
	ar(int arr[])
	{
		ar[0]=arr[0];
		ar[1]=arr[1];
	}
	public int compareTo(ar o)
	{
		return this.ar[0]>o.ar[0]?1:this.ar[0]==o.ar[0]?0:-1;
	}
}


		//						package Dynamic;
import java.io.*;
import java.util.*;
public class Main{
	static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer st;
    static public void main(String[] args)throws IOException{
    	st=new StringTokenizer(br.readLine());
    	int n=i();
    	int d=i();
    	int e=i();
    	int v=n/e;
    	v=v/5;
    	v*=5;
    	int vv=n-v*e;
    	vv=vv%d;

    	int va=n%d;
    	va=va%(5*e);
    	pl(Math.min(vv,va));
    }
    static int i()throws IOException
    {
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	return Integer.parseInt(st.nextToken());
    }
    static long l()throws IOException
    {
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	return Long.parseLong(st.nextToken());
    }
    static String s()throws IOException
    {
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	return st.nextToken();
    }
    static double d()throws IOException
    {
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	return Double.parseDouble(st.nextToken());
    }
    static void p(String p)
    {
    	System.out.print(p);
    }
    static void p(int p)
    {
    	System.out.print(p);
    }
    static void p(double p)
    {
    	System.out.print(p);
    }
    static void p(long p)
    {
    	System.out.print(p);
    }
    static void p(char p)
    {
    	System.out.print(p);
    }
    static void p(boolean p)
    {
    	System.out.print(p);
    }
    static void pl(String pl)
    {
    	System.out.println(pl);
    }
    static void pl(int pl)
    {
    	System.out.println(pl);
    }
    static void pl(char pl)
    {
    	System.out.println(pl);
    }
    static void pl(double pl)
    {
    	System.out.println(pl);
    }
    static void pl(long pl)
    {
    	System.out.println(pl);
    }
    static void pl(boolean pl)
    {
    	System.out.println(pl);
    }
    static void pl()
    {
    	System.out.println();
    }
    static int[] ari(int n)throws IOException
    {
    	int ar[]=new int[n];
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	for(int x=0;x<n;x++)
    		ar[x]=i();
    	return ar;
    }
    static long[] arl(int n)throws IOException
    {
    	long ar[]=new long[n];
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	for(int x=0;x<n;x++)
    		ar[x]=l();
    	return ar;
    }
    static String[] ars(int n)throws IOException
    {
    	String ar[]=new String[n];
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	for(int x=0;x<n;x++)
    		ar[x]=s();
    	return ar;
    }
    static double[] ard(int n)throws IOException
    {
    	double ar[]=new double[n];
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	for(int x=0;x<n;x++)
    		ar[x]=d();
    	return ar;
    }
    static char[] arc(int n)throws IOException
    {
    	char ar[]=new char[n];
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	for(int x=0;x<n;x++)
    		ar[x]=st.nextToken().charAt(0);
    	return ar;
    }
    static void pari(int ar[])
    {
    	for(int a:ar)
    		System.out.print(a+" ");
    }
    static void parl(long ar[])
    {
    	for(long a:ar)
    		System.out.print(a+" ");
    }
    static void pars(String ar[])
    {
    	for(String a:ar)
    		System.out.print(a+" ");
    }
    static void pard(double ar[])
    {
    	for(double a:ar)
    		System.out.print(a+" ");
    }
    static void parc(char ar[])
    {
    	for(char a:ar)
    		System.out.print(a+" ");
    }
}
class ar implements Comparable<ar>
{
	int ar[]=new int[2];
	ar(int arr[])
	{
		ar[0]=arr[0];
		ar[1]=arr[1];
	}
	public int compareTo(ar o)
	{
		return this.ar[0]>o.ar[0]?1:this.ar[0]==o.ar[0]?0:-1;
	}
}


				//				package Dynamic;
import java.io.*;
import java.util.*;
public class Main{
	static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer st;
    static public void main(String[] args)throws IOException{
    	st=new StringTokenizer(br.readLine());
    	int n=i();
    	int d=i();
    	int e=5*i();
    	int x=Math.max(d,e);
    	int y=Math.min(d,e);
    	int min=Integer.MAX_VALUE;
    	int val=n;
    	n-=x;
    	while(n>0)
    	{

    		min=Math.min(min,n%y);
    		if(min==0)	break;
    		n-=x;
    	}

    	pl(Math.min(min,val%y));
    }
    static int i()throws IOException
    {
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	return Integer.parseInt(st.nextToken());
    }
    static long l()throws IOException
    {
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	return Long.parseLong(st.nextToken());
    }
    static String s()throws IOException
    {
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	return st.nextToken();
    }
    static double d()throws IOException
    {
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	return Double.parseDouble(st.nextToken());
    }
    static void p(String p)
    {
    	System.out.print(p);
    }
    static void p(int p)
    {
    	System.out.print(p);
    }
    static void p(double p)
    {
    	System.out.print(p);
    }
    static void p(long p)
    {
    	System.out.print(p);
    }
    static void p(char p)
    {
    	System.out.print(p);
    }
    static void p(boolean p)
    {
    	System.out.print(p);
    }
    static void pl(String pl)
    {
    	System.out.println(pl);
    }
    static void pl(int pl)
    {
    	System.out.println(pl);
    }
    static void pl(char pl)
    {
    	System.out.println(pl);
    }
    static void pl(double pl)
    {
    	System.out.println(pl);
    }
    static void pl(long pl)
    {
    	System.out.println(pl);
    }
    static void pl(boolean pl)
    {
    	System.out.println(pl);
    }
    static void pl()
    {
    	System.out.println();
    }
    static int[] ari(int n)throws IOException
    {
    	int ar[]=new int[n];
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	for(int x=0;x<n;x++)
    		ar[x]=i();
    	return ar;
    }
    static long[] arl(int n)throws IOException
    {
    	long ar[]=new long[n];
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	for(int x=0;x<n;x++)
    		ar[x]=l();
    	return ar;
    }
    static String[] ars(int n)throws IOException
    {
    	String ar[]=new String[n];
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	for(int x=0;x<n;x++)
    		ar[x]=s();
    	return ar;
    }
    static double[] ard(int n)throws IOException
    {
    	double ar[]=new double[n];
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	for(int x=0;x<n;x++)
    		ar[x]=d();
    	return ar;
    }
    static char[] arc(int n)throws IOException
    {
    	char ar[]=new char[n];
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	for(int x=0;x<n;x++)
    		ar[x]=st.nextToken().charAt(0);
    	return ar;
    }
    static void pari(int ar[])
    {
    	for(int a:ar)
    		System.out.print(a+" ");
    }
    static void parl(long ar[])
    {
    	for(long a:ar)
    		System.out.print(a+" ");
    }
    static void pars(String ar[])
    {
    	for(String a:ar)
    		System.out.print(a+" ");
    }
    static void pard(double ar[])
    {
    	for(double a:ar)
    		System.out.print(a+" ");
    }
    static void parc(char ar[])
    {
    	for(char a:ar)
    		System.out.print(a+" ");
    }
}
class ar implements Comparable<ar>
{
	int ar[]=new int[2];
	ar(int arr[])
	{
		ar[0]=arr[0];
		ar[1]=arr[1];
	}
	public int compareTo(ar o)
	{
		return this.ar[0]>o.ar[0]?1:this.ar[0]==o.ar[0]?0:-1;
	}
}


							//	package Dynamic;
import java.io.*;
import java.util.*;
public class Main{
	static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer st;
    static public void main(String[] args)throws IOException{
    	st=new StringTokenizer(br.readLine());
    	int n=i();
    	int d=i();
    	int e=5*i();
    	int x=Math.max(d,e);
    	int y=Math.min(d,e);
    	int min=Integer.MAX_VALUE;
    	int val=n;
    	n-=x;
    	while(n>=0)
    	{

    		min=Math.min(min,n%y);
    		if(min==0)
    			{
    			pl(0);
    				System.exit(0);
    			}
    		n-=x;
    	}
    	n=val;
    	n-=y;
    	//pl(min);
    	while(n>=0)
    	{

    		min=Math.min(min,n%x);
    		//pl(n+" "+min);
    		if(min==0){
    			pl(0);
				System.exit(0);
			}
    		n-=y;
    	}

    	pl(min);
    }
    static int i()throws IOException
    {
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	return Integer.parseInt(st.nextToken());
    }
    static long l()throws IOException
    {
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	return Long.parseLong(st.nextToken());
    }
    static String s()throws IOException
    {
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	return st.nextToken();
    }
    static double d()throws IOException
    {
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	return Double.parseDouble(st.nextToken());
    }
    static void p(String p)
    {
    	System.out.print(p);
    }
    static void p(int p)
    {
    	System.out.print(p);
    }
    static void p(double p)
    {
    	System.out.print(p);
    }
    static void p(long p)
    {
    	System.out.print(p);
    }
    static void p(char p)
    {
    	System.out.print(p);
    }
    static void p(boolean p)
    {
    	System.out.print(p);
    }
    static void pl(String pl)
    {
    	System.out.println(pl);
    }
    static void pl(int pl)
    {
    	System.out.println(pl);
    }
    static void pl(char pl)
    {
    	System.out.println(pl);
    }
    static void pl(double pl)
    {
    	System.out.println(pl);
    }
    static void pl(long pl)
    {
    	System.out.println(pl);
    }
    static void pl(boolean pl)
    {
    	System.out.println(pl);
    }
    static void pl()
    {
    	System.out.println();
    }
    static int[] ari(int n)throws IOException
    {
    	int ar[]=new int[n];
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	for(int x=0;x<n;x++)
    		ar[x]=i();
    	return ar;
    }
    static long[] arl(int n)throws IOException
    {
    	long ar[]=new long[n];
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	for(int x=0;x<n;x++)
    		ar[x]=l();
    	return ar;
    }
    static String[] ars(int n)throws IOException
    {
    	String ar[]=new String[n];
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	for(int x=0;x<n;x++)
    		ar[x]=s();
    	return ar;
    }
    static double[] ard(int n)throws IOException
    {
    	double ar[]=new double[n];
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	for(int x=0;x<n;x++)
    		ar[x]=d();
    	return ar;
    }
    static char[] arc(int n)throws IOException
    {
    	char ar[]=new char[n];
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	for(int x=0;x<n;x++)
    		ar[x]=st.nextToken().charAt(0);
    	return ar;
    }
    static void pari(int ar[])
    {
    	for(int a:ar)
    		System.out.print(a+" ");
    }
    static void parl(long ar[])
    {
    	for(long a:ar)
    		System.out.print(a+" ");
    }
    static void pars(String ar[])
    {
    	for(String a:ar)
    		System.out.print(a+" ");
    }
    static void pard(double ar[])
    {
    	for(double a:ar)
    		System.out.print(a+" ");
    }
    static void parc(char ar[])
    {
    	for(char a:ar)
    		System.out.print(a+" ");
    }
}
class ar implements Comparable<ar>
{
	int ar[]=new int[2];
	ar(int arr[])
	{
		ar[0]=arr[0];
		ar[1]=arr[1];
	}
	public int compareTo(ar o)
	{
		return this.ar[0]>o.ar[0]?1:this.ar[0]==o.ar[0]?0:-1;
	}
}


					//			package Dynamic;
import java.io.*;
import java.util.*;
public class Main{
	static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer st;
    static public void main(String[] args)throws IOException{
    	st=new StringTokenizer(br.readLine());
    	int n=i();
    	int d=i();
    	int e=i();
    	int v=n%(5*e);
    	v=v%d;

    	int va=n%d;
    	va=va%(5*e);
    	pl(Math.min(v,va));
    }
    static int i()throws IOException
    {
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	return Integer.parseInt(st.nextToken());
    }
    static long l()throws IOException
    {
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	return Long.parseLong(st.nextToken());
    }
    static String s()throws IOException
    {
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	return st.nextToken();
    }
    static double d()throws IOException
    {
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	return Double.parseDouble(st.nextToken());
    }
    static void p(String p)
    {
    	System.out.print(p);
    }
    static void p(int p)
    {
    	System.out.print(p);
    }
    static void p(double p)
    {
    	System.out.print(p);
    }
    static void p(long p)
    {
    	System.out.print(p);
    }
    static void p(char p)
    {
    	System.out.print(p);
    }
    static void p(boolean p)
    {
    	System.out.print(p);
    }
    static void pl(String pl)
    {
    	System.out.println(pl);
    }
    static void pl(int pl)
    {
    	System.out.println(pl);
    }
    static void pl(char pl)
    {
    	System.out.println(pl);
    }
    static void pl(double pl)
    {
    	System.out.println(pl);
    }
    static void pl(long pl)
    {
    	System.out.println(pl);
    }
    static void pl(boolean pl)
    {
    	System.out.println(pl);
    }
    static void pl()
    {
    	System.out.println();
    }
    static int[] ari(int n)throws IOException
    {
    	int ar[]=new int[n];
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	for(int x=0;x<n;x++)
    		ar[x]=i();
    	return ar;
    }
    static long[] arl(int n)throws IOException
    {
    	long ar[]=new long[n];
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	for(int x=0;x<n;x++)
    		ar[x]=l();
    	return ar;
    }
    static String[] ars(int n)throws IOException
    {
    	String ar[]=new String[n];
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	for(int x=0;x<n;x++)
    		ar[x]=s();
    	return ar;
    }
    static double[] ard(int n)throws IOException
    {
    	double ar[]=new double[n];
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	for(int x=0;x<n;x++)
    		ar[x]=d();
    	return ar;
    }
    static char[] arc(int n)throws IOException
    {
    	char ar[]=new char[n];
    	if(!st.hasMoreTokens())
    		st=new StringTokenizer(br.readLine());
    	for(int x=0;x<n;x++)
    		ar[x]=st.nextToken().charAt(0);
    	return ar;
    }
    static void pari(int ar[])
    {
    	for(int a:ar)
    		System.out.print(a+" ");
    }
    static void parl(long ar[])
    {
    	for(long a:ar)
    		System.out.print(a+" ");
    }
    static void pars(String ar[])
    {
    	for(String a:ar)
    		System.out.print(a+" ");
    }
    static void pard(double ar[])
    {
    	for(double a:ar)
    		System.out.print(a+" ");
    }
    static void parc(char ar[])
    {
    	for(char a:ar)
    		System.out.print(a+" ");
    }
}
class ar implements Comparable<ar>
{
	int ar[]=new int[2];
	ar(int arr[])
	{
		ar[0]=arr[0];
		ar[1]=arr[1];
	}
	public int compareTo(ar o)
	{
		return this.ar[0]>o.ar[0]?1:this.ar[0]==o.ar[0]?0:-1;
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.util.*;

public class Main {
	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;
		}
	}

	public static void main(String[] args) throws IOException{
		FastReader in=new FastReader();
		BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));
		long n = in.nextLong();
                int d = in.nextInt();
                int e = in.nextInt();
                if(n%d == 0 || n%(e*5)==0)
                    log.write(0+"\n");
                else if(e * 5 > n){
                    log.write(n%d + "\n");
                }else {
                    long res = Long.min((n%(e*5))%d, n%d);
                    log.write(res+"\n");
                }

		log.flush();
		log.close();

	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.util.*;

public class Main {
	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;
		}
	}

	public static void main(String[] args) throws IOException{
		FastReader in=new FastReader();
		BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));
		long n = in.nextLong();
                int d = in.nextInt();
                int e = in.nextInt();
                if(n%d == 0 || n%(e*5)==0)
                    log.write(0+"\n");
                else if(e * 5 > n){
                    log.write(n%d + "\n");
                }else {
                    long res = n;
                    for(int i = 0; i*5*e<n; i++){
                        res = Long.min(res, (n-i*e*5)%d);
                    }
                    log.write(res+"\n");
                }

		log.flush();
		log.close();

	}
}


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

public class Main {
    static PrintWriter pw;
    static Scanner sc;
    static long ceildiv(long x, long y) { return (x+y-1)/y; }
    static int mod(long x, int m) { return (int)((x%m+m)%m); }
    static void put(TreeMap<Integer, Integer> map, Integer p){if(map.containsKey(p)) map.replace(p, map.get(p)+1); else map.put(p, 1); }
    static void rem(TreeMap<Integer, Integer> map, Integer p){ if(map.get(p)==1) map.remove(p);else map.replace(p, map.get(p)-1); }
    static long gcd(long x, long y) {return y==0?x:gcd(y, x%y);}
    static int Int(boolean x){ return x?1:0; }
    static int mod=998244353, inf=(int)1e9;
    static long[] fact;
    public static void main(String[] args) throws Exception {
        sc = new Scanner(System.in);
        pw=new PrintWriter(System.out);
        int n=sc.nextInt(), d=sc.nextInt(), e=sc.nextInt();
        int x=d, y=5*e;
        if(n%gcd(x, y)!=0){
            pw.println(Math.min((n%x)%y, (n%y)%x));
        }else{
            pw.println(0);
        }
        pw.close();
    }
    static Main.Pair Euclid(int x, int y){
        if(y==0)
            return new Main.Pair(1, 0);
        Main.Pair p=Euclid(y, x%y);
        int a=p.y, b=(int)(p.x-p.y*1l*(x/y));
        return new Main.Pair(a, b);
    }
    static void floyd(int[][] arr, int[][] par){
        for(int i=0; i<arr.length; i++){
            for(int j=0; j<arr.length; j++){
                for(int k=0; k<arr.length; k++){
                    if(arr[j][k]>arr[j][i]+arr[i][k]){
                        par[j][k]=par[i][k];
                        arr[j][k]=arr[j][i]+arr[i][k];
                    }
                }
            }
        }
    }
    static void printArr(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++)
            pw.print(arr[i] + " ");
        pw.println(arr[arr.length - 1]);
    }
    static void printArr(long[] arr) {
        for (int i = 0; i < arr.length - 1; i++)
            pw.print(arr[i] + " ");
        pw.println(arr[arr.length - 1]);
    }
    static void printArr(Integer[] arr) {
        for (int i = 0; i < arr.length; i++)
            pw.print(arr[i] + " ");
        pw.println();
    }
    static void printArr(char[] arr) {
        for (int i = 0; i < arr.length; i++)
            pw.print(arr[i]==0? '1': arr[i]);
        pw.println();
    }
    static void printArr(ArrayList<Integer> list) {
        for (int i = 0; i < list.size(); i++)
            pw.print(list.get(i)+" ");
        pw.println();
    }
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;
        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

        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 {
            return Double.parseDouble(next());
        }

        public int[] nextArr(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++)
                arr[i] = nextInt();
            return arr;
        }
        public Integer[] nextsort(int n) throws IOException{
            Integer[] arr=new Integer[n];
            for(int i=0; i<n; i++)
                arr[i]=nextInt();
            return arr;
        }
        public Pair nextPair() throws IOException{
            return new Pair(nextInt(), nextInt());
        }
        public Pair[] nextPairArr(int n) throws IOException{
            Pair[] arr=new Pair[n];
            for(int i=0; i<n; i++)
                arr[i]=nextPair();
            return arr;
        }
        public boolean ready() throws IOException {
            return br.ready();
        }
    }
    static class Pair implements Comparable<Pair>{
        int x;
        int y;
        public Pair(int x, int y) {
            this.x=x;
            this.y=y;
        }
        public int hashCode() {
            return (this.x*1000+this.y);
        }
        public int compareTo(Pair p){
            if(x!=p.x)
                return x-p.x;
            return p.y-y;
        }
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (this.getClass() != obj.getClass()) {
                return false;
            }
            Pair p = (Pair) obj;
            return this.x==p.x && this.y==p.y;
        }
        public Pair clone(){
            return new Pair(x, y);
        }
        public String toString(){
            return this.x+" "+this.y;
        }
        public void add(Pair p){
            x+=p.x;
            y+=p.y;
        }
    }
}


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

public class Main {
    static PrintWriter pw;
    static Scanner sc;
    static long ceildiv(long x, long y) { return (x+y-1)/y; }
    static int mod(long x, int m) { return (int)((x%m+m)%m); }
    static void put(TreeMap<Integer, Integer> map, Integer p){if(map.containsKey(p)) map.replace(p, map.get(p)+1); else map.put(p, 1); }
    static void rem(TreeMap<Integer, Integer> map, Integer p){ if(map.get(p)==1) map.remove(p);else map.replace(p, map.get(p)-1); }
    static long gcd(long x, long y) {return y==0?x:gcd(y, x%y);}
    static int Int(boolean x){ return x?1:0; }
    static int mod=998244353, inf=(int)1e9;
    static long[] fact;
    public static void main(String[] args) throws Exception {
        sc = new Scanner(System.in);
        pw=new PrintWriter(System.out);
        int n=sc.nextInt(), a=sc.nextInt(), b=5*sc.nextInt();
        int temp=n;
        int ans=n;
        while(temp>a){
            ans=Math.min(ans, temp%b);
            temp-=a;
        }
        ans=Math.min(temp%b, ans);
        while(n>b){
            ans=Math.min(ans, n%a);
            temp-=b;
        }
        ans=Math.min(n%a, ans);
        pw.println(ans);
        pw.close();
    }
    static Main.Pair Euclid(int x, int y){
        if(y==0)
            return new Main.Pair(1, 0);
        Main.Pair p=Euclid(y, x%y);
        int a=p.y, b=(int)(p.x-p.y*1l*(x/y));
        return new Main.Pair(a, b);
    }
    static void floyd(int[][] arr, int[][] par){
        for(int i=0; i<arr.length; i++){
            for(int j=0; j<arr.length; j++){
                for(int k=0; k<arr.length; k++){
                    if(arr[j][k]>arr[j][i]+arr[i][k]){
                        par[j][k]=par[i][k];
                        arr[j][k]=arr[j][i]+arr[i][k];
                    }
                }
            }
        }
    }
    static void printArr(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++)
            pw.print(arr[i] + " ");
        pw.println(arr[arr.length - 1]);
    }
    static void printArr(long[] arr) {
        for (int i = 0; i < arr.length - 1; i++)
            pw.print(arr[i] + " ");
        pw.println(arr[arr.length - 1]);
    }
    static void printArr(Integer[] arr) {
        for (int i = 0; i < arr.length; i++)
            pw.print(arr[i] + " ");
        pw.println();
    }
    static void printArr(char[] arr) {
        for (int i = 0; i < arr.length; i++)
            pw.print(arr[i]==0? '1': arr[i]);
        pw.println();
    }
    static void printArr(ArrayList<Integer> list) {
        for (int i = 0; i < list.size(); i++)
            pw.print(list.get(i)+" ");
        pw.println();
    }
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;
        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

        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 {
            return Double.parseDouble(next());
        }

        public int[] nextArr(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++)
                arr[i] = nextInt();
            return arr;
        }
        public Integer[] nextsort(int n) throws IOException{
            Integer[] arr=new Integer[n];
            for(int i=0; i<n; i++)
                arr[i]=nextInt();
            return arr;
        }
        public Pair nextPair() throws IOException{
            return new Pair(nextInt(), nextInt());
        }
        public Pair[] nextPairArr(int n) throws IOException{
            Pair[] arr=new Pair[n];
            for(int i=0; i<n; i++)
                arr[i]=nextPair();
            return arr;
        }
        public boolean ready() throws IOException {
            return br.ready();
        }
    }
    static class Pair implements Comparable<Pair>{
        int x;
        int y;
        public Pair(int x, int y) {
            this.x=x;
            this.y=y;
        }
        public int hashCode() {
            return (this.x*1000+this.y);
        }
        public int compareTo(Pair p){
            if(x!=p.x)
                return x-p.x;
            return p.y-y;
        }
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (this.getClass() != obj.getClass()) {
                return false;
            }
            Pair p = (Pair) obj;
            return this.x==p.x && this.y==p.y;
        }
        public Pair clone(){
            return new Pair(x, y);
        }
        public String toString(){
            return this.x+" "+this.y;
        }
        public void add(Pair p){
            x+=p.x;
            y+=p.y;
        }
    }
}


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

public class Main {
    static PrintWriter pw;
    static Scanner sc;
    static long ceildiv(long x, long y) { return (x+y-1)/y; }
    static int mod(long x, int m) { return (int)((x%m+m)%m); }
    static void put(TreeMap<Integer, Integer> map, Integer p){if(map.containsKey(p)) map.replace(p, map.get(p)+1); else map.put(p, 1); }
    static void rem(TreeMap<Integer, Integer> map, Integer p){ if(map.get(p)==1) map.remove(p);else map.replace(p, map.get(p)-1); }
    static long gcd(long x, long y) {return y==0?x:gcd(y, x%y);}
    static int Int(boolean x){ return x?1:0; }
    static int mod=998244353, inf=(int)1e9;
    static long[] fact;
    public static void main(String[] args) throws Exception {
        sc = new Scanner(System.in);
        pw=new PrintWriter(System.out);
        int n=sc.nextInt(), d=sc.nextInt(), e=sc.nextInt();
        int x=d, y=5*e;
        if(n%gcd(x, y)!=0){
            pw.println(Math.min((n%x)%y, (n%y)%x));
        }else{
            Pair p=Euclid(x, y);
            int lcm=x*y/(int)gcd(x,y);
            int a=lcm/x, b=lcm/y;
            if(p.x<0){
                int diff=(int)ceildiv(Math.abs(p.x), a);
                p.x+=diff*a;
                p.y-=diff*a;
            }else if(p.y<0){
                int diff=(int)ceildiv(Math.abs(p.y), a);
                p.x-=diff*a;
                p.y+=diff*a;
            }
            if(p.x<0 || p.y<0 || n%lcm!=0)
                pw.println(Math.min((n%x)%y, (n%y)%x));
            else
                pw.println(0);
        }
        pw.close();
    }
    static Main.Pair Euclid(int x, int y){
        if(y==0)
            return new Main.Pair(1, 0);
        Main.Pair p=Euclid(y, x%y);
        int a=p.y, b=(int)(p.x-p.y*1l*(x/y));
        return new Main.Pair(a, b);
    }
    static void floyd(int[][] arr, int[][] par){
        for(int i=0; i<arr.length; i++){
            for(int j=0; j<arr.length; j++){
                for(int k=0; k<arr.length; k++){
                    if(arr[j][k]>arr[j][i]+arr[i][k]){
                        par[j][k]=par[i][k];
                        arr[j][k]=arr[j][i]+arr[i][k];
                    }
                }
            }
        }
    }
    static void printArr(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++)
            pw.print(arr[i] + " ");
        pw.println(arr[arr.length - 1]);
    }
    static void printArr(long[] arr) {
        for (int i = 0; i < arr.length - 1; i++)
            pw.print(arr[i] + " ");
        pw.println(arr[arr.length - 1]);
    }
    static void printArr(Integer[] arr) {
        for (int i = 0; i < arr.length; i++)
            pw.print(arr[i] + " ");
        pw.println();
    }
    static void printArr(char[] arr) {
        for (int i = 0; i < arr.length; i++)
            pw.print(arr[i]==0? '1': arr[i]);
        pw.println();
    }
    static void printArr(ArrayList<Integer> list) {
        for (int i = 0; i < list.size(); i++)
            pw.print(list.get(i)+" ");
        pw.println();
    }
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;
        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

        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 {
            return Double.parseDouble(next());
        }

        public int[] nextArr(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++)
                arr[i] = nextInt();
            return arr;
        }
        public Integer[] nextsort(int n) throws IOException{
            Integer[] arr=new Integer[n];
            for(int i=0; i<n; i++)
                arr[i]=nextInt();
            return arr;
        }
        public Pair nextPair() throws IOException{
            return new Pair(nextInt(), nextInt());
        }
        public Pair[] nextPairArr(int n) throws IOException{
            Pair[] arr=new Pair[n];
            for(int i=0; i<n; i++)
                arr[i]=nextPair();
            return arr;
        }
        public boolean ready() throws IOException {
            return br.ready();
        }
    }
    static class Pair implements Comparable<Pair>{
        int x;
        int y;
        public Pair(int x, int y) {
            this.x=x;
            this.y=y;
        }
        public int hashCode() {
            return (this.x*1000+this.y);
        }
        public int compareTo(Pair p){
            if(x!=p.x)
                return x-p.x;
            return p.y-y;
        }
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (this.getClass() != obj.getClass()) {
                return false;
            }
            Pair p = (Pair) obj;
            return this.x==p.x && this.y==p.y;
        }
        public Pair clone(){
            return new Pair(x, y);
        }
        public String toString(){
            return this.x+" "+this.y;
        }
        public void add(Pair p){
            x+=p.x;
            y+=p.y;
        }
    }
}


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

public class Main {
    static PrintWriter pw;
    static Scanner sc;
    static long ceildiv(long x, long y) { return (x+y-1)/y; }
    static int mod(long x, int m) { return (int)((x%m+m)%m); }
    static void put(TreeMap<Integer, Integer> map, Integer p){if(map.containsKey(p)) map.replace(p, map.get(p)+1); else map.put(p, 1); }
    static void rem(TreeMap<Integer, Integer> map, Integer p){ if(map.get(p)==1) map.remove(p);else map.replace(p, map.get(p)-1); }
    static long gcd(long x, long y) {return y==0?x:gcd(y, x%y);}
    static int Int(boolean x){ return x?1:0; }
    static int mod=998244353, inf=(int)1e9;
    static long[] fact;
    public static void main(String[] args) throws Exception {
        sc = new Scanner(System.in);
        pw=new PrintWriter(System.out);
        int n=sc.nextInt(), d=sc.nextInt(), e=sc.nextInt();
        TreeSet<Integer> ch=new TreeSet<>();
        int x=d, y=5*e;
        pw.println(Math.min((n%x)%y, (n%y)%x));
        pw.close();
    }
    static void floyd(int[][] arr, int[][] par){
        for(int i=0; i<arr.length; i++){
            for(int j=0; j<arr.length; j++){
                for(int k=0; k<arr.length; k++){
                    if(arr[j][k]>arr[j][i]+arr[i][k]){
                        par[j][k]=par[i][k];
                        arr[j][k]=arr[j][i]+arr[i][k];
                    }
                }
            }
        }
    }
    static void printArr(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++)
            pw.print(arr[i] + " ");
        pw.println(arr[arr.length - 1]);
    }
    static void printArr(long[] arr) {
        for (int i = 0; i < arr.length - 1; i++)
            pw.print(arr[i] + " ");
        pw.println(arr[arr.length - 1]);
    }
    static void printArr(Integer[] arr) {
        for (int i = 0; i < arr.length; i++)
            pw.print(arr[i] + " ");
        pw.println();
    }
    static void printArr(char[] arr) {
        for (int i = 0; i < arr.length; i++)
            pw.print(arr[i]==0? '1': arr[i]);
        pw.println();
    }
    static void printArr(ArrayList<Integer> list) {
        for (int i = 0; i < list.size(); i++)
            pw.print(list.get(i)+" ");
        pw.println();
    }
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;
        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

        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 {
            return Double.parseDouble(next());
        }

        public int[] nextArr(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++)
                arr[i] = nextInt();
            return arr;
        }
        public Integer[] nextsort(int n) throws IOException{
            Integer[] arr=new Integer[n];
            for(int i=0; i<n; i++)
                arr[i]=nextInt();
            return arr;
        }
        public Pair nextPair() throws IOException{
            return new Pair(nextInt(), nextInt());
        }
        public Pair[] nextPairArr(int n) throws IOException{
            Pair[] arr=new Pair[n];
            for(int i=0; i<n; i++)
                arr[i]=nextPair();
            return arr;
        }
        public boolean ready() throws IOException {
            return br.ready();
        }
    }
    static class Pair implements Comparable<Pair>{
        int x;
        int y;
        public Pair(int x, int y) {
            this.x=x;
            this.y=y;
        }
        public int hashCode() {
            return (this.x*1000+this.y);
        }
        public int compareTo(Pair p){
            if(x!=p.x)
                return x-p.x;
            return p.y-y;
        }
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (this.getClass() != obj.getClass()) {
                return false;
            }
            Pair p = (Pair) obj;
            return this.x==p.x && this.y==p.y;
        }
        public Pair clone(){
            return new Pair(x, y);
        }
        public String toString(){
            return this.x+" "+this.y;
        }
        public void add(Pair p){
            x+=p.x;
            y+=p.y;
        }
    }
}


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

public class Main {
    static PrintWriter pw;
    static Scanner sc;
    static long ceildiv(long x, long y) { return (x+y-1)/y; }
    static int mod(long x, int m) { return (int)((x%m+m)%m); }
    static void put(TreeMap<Integer, Integer> map, Integer p){if(map.containsKey(p)) map.replace(p, map.get(p)+1); else map.put(p, 1); }
    static void rem(TreeMap<Integer, Integer> map, Integer p){ if(map.get(p)==1) map.remove(p);else map.replace(p, map.get(p)-1); }
    static long gcd(long x, long y) {return y==0?x:gcd(y, x%y);}
    static int Int(boolean x){ return x?1:0; }
    static int mod=998244353, inf=(int)1e9;
    static long[] fact;
    public static void main(String[] args) throws Exception {
        sc = new Scanner(System.in);
        pw=new PrintWriter(System.out);
        int n=sc.nextInt(), a=sc.nextInt(), b=5*sc.nextInt();
        int temp=n;
        int ans=n;
        while(temp>a){
            ans=Math.min(ans, temp%b);
            temp-=a;
        }
        ans=Math.min(temp%b, ans);
        while(n>b){
            ans=Math.min(ans, n%a);
            n-=b;
        }
        ans=Math.min(n%a, ans);
        pw.println(ans);
        pw.close();
    }
    static Main.Pair Euclid(int x, int y){
        if(y==0)
            return new Main.Pair(1, 0);
        Main.Pair p=Euclid(y, x%y);
        int a=p.y, b=(int)(p.x-p.y*1l*(x/y));
        return new Main.Pair(a, b);
    }
    static void floyd(int[][] arr, int[][] par){
        for(int i=0; i<arr.length; i++){
            for(int j=0; j<arr.length; j++){
                for(int k=0; k<arr.length; k++){
                    if(arr[j][k]>arr[j][i]+arr[i][k]){
                        par[j][k]=par[i][k];
                        arr[j][k]=arr[j][i]+arr[i][k];
                    }
                }
            }
        }
    }
    static void printArr(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++)
            pw.print(arr[i] + " ");
        pw.println(arr[arr.length - 1]);
    }
    static void printArr(long[] arr) {
        for (int i = 0; i < arr.length - 1; i++)
            pw.print(arr[i] + " ");
        pw.println(arr[arr.length - 1]);
    }
    static void printArr(Integer[] arr) {
        for (int i = 0; i < arr.length; i++)
            pw.print(arr[i] + " ");
        pw.println();
    }
    static void printArr(char[] arr) {
        for (int i = 0; i < arr.length; i++)
            pw.print(arr[i]==0? '1': arr[i]);
        pw.println();
    }
    static void printArr(ArrayList<Integer> list) {
        for (int i = 0; i < list.size(); i++)
            pw.print(list.get(i)+" ");
        pw.println();
    }
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;
        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

        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 {
            return Double.parseDouble(next());
        }

        public int[] nextArr(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++)
                arr[i] = nextInt();
            return arr;
        }
        public Integer[] nextsort(int n) throws IOException{
            Integer[] arr=new Integer[n];
            for(int i=0; i<n; i++)
                arr[i]=nextInt();
            return arr;
        }
        public Pair nextPair() throws IOException{
            return new Pair(nextInt(), nextInt());
        }
        public Pair[] nextPairArr(int n) throws IOException{
            Pair[] arr=new Pair[n];
            for(int i=0; i<n; i++)
                arr[i]=nextPair();
            return arr;
        }
        public boolean ready() throws IOException {
            return br.ready();
        }
    }
    static class Pair implements Comparable<Pair>{
        int x;
        int y;
        public Pair(int x, int y) {
            this.x=x;
            this.y=y;
        }
        public int hashCode() {
            return (this.x*1000+this.y);
        }
        public int compareTo(Pair p){
            if(x!=p.x)
                return x-p.x;
            return p.y-y;
        }
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (this.getClass() != obj.getClass()) {
                return false;
            }
            Pair p = (Pair) obj;
            return this.x==p.x && this.y==p.y;
        }
        public Pair clone(){
            return new Pair(x, y);
        }
        public String toString(){
            return this.x+" "+this.y;
        }
        public void add(Pair p){
            x+=p.x;
            y+=p.y;
        }
    }
}


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

public class Main {
    static PrintWriter pw;
    static Scanner sc;
    static long ceildiv(long x, long y) { return (x+y-1)/y; }
    static int mod(long x, int m) { return (int)((x%m+m)%m); }
    static void put(TreeMap<Integer, Integer> map, Integer p){if(map.containsKey(p)) map.replace(p, map.get(p)+1); else map.put(p, 1); }
    static void rem(TreeMap<Integer, Integer> map, Integer p){ if(map.get(p)==1) map.remove(p);else map.replace(p, map.get(p)-1); }
    static long gcd(long x, long y) {return y==0?x:gcd(y, x%y);}
    static int Int(boolean x){ return x?1:0; }
    static int mod=998244353, inf=(int)1e9;
    static long[] fact;
    public static void main(String[] args) throws Exception {
        sc = new Scanner(System.in);
        pw=new PrintWriter(System.out);
        int n=sc.nextInt(), d=sc.nextInt(), e=sc.nextInt();
        TreeSet<Integer> ch=new TreeSet<>();
        ch.add(d); ch.add(2*d); ch.add(5*d); ch.add(10*d); ch.add(20*d); ch.add(50*d); ch.add(100*d);
        ch.add(5*e); ch.add(10*e); ch.add(20*e); ch.add(50*e); ch.add(100*e); ch.add(200*e);
        int min=ch.first();
        while(n>=min)
            n-=ch.floor(n);
        pw.println(n);
        pw.close();
    }
    static void floyd(int[][] arr, int[][] par){
        for(int i=0; i<arr.length; i++){
            for(int j=0; j<arr.length; j++){
                for(int k=0; k<arr.length; k++){
                    if(arr[j][k]>arr[j][i]+arr[i][k]){
                        par[j][k]=par[i][k];
                        arr[j][k]=arr[j][i]+arr[i][k];
                    }
                }
            }
        }
    }
    static void printArr(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++)
            pw.print(arr[i] + " ");
        pw.println(arr[arr.length - 1]);
    }
    static void printArr(long[] arr) {
        for (int i = 0; i < arr.length - 1; i++)
            pw.print(arr[i] + " ");
        pw.println(arr[arr.length - 1]);
    }
    static void printArr(Integer[] arr) {
        for (int i = 0; i < arr.length; i++)
            pw.print(arr[i] + " ");
        pw.println();
    }
    static void printArr(char[] arr) {
        for (int i = 0; i < arr.length; i++)
            pw.print(arr[i]==0? '1': arr[i]);
        pw.println();
    }
    static void printArr(ArrayList<Integer> list) {
        for (int i = 0; i < list.size(); i++)
            pw.print(list.get(i)+" ");
        pw.println();
    }
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;
        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

        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 {
            return Double.parseDouble(next());
        }

        public int[] nextArr(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++)
                arr[i] = nextInt();
            return arr;
        }
        public Integer[] nextsort(int n) throws IOException{
            Integer[] arr=new Integer[n];
            for(int i=0; i<n; i++)
                arr[i]=nextInt();
            return arr;
        }
        public Pair nextPair() throws IOException{
            return new Pair(nextInt(), nextInt());
        }
        public Pair[] nextPairArr(int n) throws IOException{
            Pair[] arr=new Pair[n];
            for(int i=0; i<n; i++)
                arr[i]=nextPair();
            return arr;
        }
        public boolean ready() throws IOException {
            return br.ready();
        }
    }
    static class Pair implements Comparable<Pair>{
        int x;
        int y;
        public Pair(int x, int y) {
            this.x=x;
            this.y=y;
        }
        public int hashCode() {
            return (this.x*1000+this.y);
        }
        public int compareTo(Pair p){
            if(x!=p.x)
                return x-p.x;
            return p.y-y;
        }
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (this.getClass() != obj.getClass()) {
                return false;
            }
            Pair p = (Pair) obj;
            return this.x==p.x && this.y==p.y;
        }
        public Pair clone(){
            return new Pair(x, y);
        }
        public String toString(){
            return this.x+" "+this.y;
        }
        public void add(Pair p){
            x+=p.x;
            y+=p.y;
        }
    }
}


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

public class Main {
    static PrintWriter pw;
    static Scanner sc;
    static long ceildiv(long x, long y) { return (x+y-1)/y; }
    static int mod(long x, int m) { return (int)((x%m+m)%m); }
    static void put(TreeMap<Integer, Integer> map, Integer p){if(map.containsKey(p)) map.replace(p, map.get(p)+1); else map.put(p, 1); }
    static void rem(TreeMap<Integer, Integer> map, Integer p){ if(map.get(p)==1) map.remove(p);else map.replace(p, map.get(p)-1); }
    static long gcd(long x, long y) {return y==0?x:gcd(y, x%y);}
    static int Int(boolean x){ return x?1:0; }
    static int mod=998244353, inf=(int)1e9;
    static long[] fact;
    public static void main(String[] args) throws Exception {
        sc = new Scanner(System.in);
        pw=new PrintWriter(System.out);
        int n=sc.nextInt(), a=sc.nextInt(), b=5*sc.nextInt();
        boolean f, sec;
        int temp=n;
        while(temp%b!=0 && temp>a)
            temp-=a;
        f=temp%b==0;
        while(n%a!=0 && n>b)
            n-=b;
        sec=n%a==0;
        pw.println(f || sec?0:Math.min((n%a)%b, (n%b)%a));
        pw.close();
    }
    static Main.Pair Euclid(int x, int y){
        if(y==0)
            return new Main.Pair(1, 0);
        Main.Pair p=Euclid(y, x%y);
        int a=p.y, b=(int)(p.x-p.y*1l*(x/y));
        return new Main.Pair(a, b);
    }
    static void floyd(int[][] arr, int[][] par){
        for(int i=0; i<arr.length; i++){
            for(int j=0; j<arr.length; j++){
                for(int k=0; k<arr.length; k++){
                    if(arr[j][k]>arr[j][i]+arr[i][k]){
                        par[j][k]=par[i][k];
                        arr[j][k]=arr[j][i]+arr[i][k];
                    }
                }
            }
        }
    }
    static void printArr(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++)
            pw.print(arr[i] + " ");
        pw.println(arr[arr.length - 1]);
    }
    static void printArr(long[] arr) {
        for (int i = 0; i < arr.length - 1; i++)
            pw.print(arr[i] + " ");
        pw.println(arr[arr.length - 1]);
    }
    static void printArr(Integer[] arr) {
        for (int i = 0; i < arr.length; i++)
            pw.print(arr[i] + " ");
        pw.println();
    }
    static void printArr(char[] arr) {
        for (int i = 0; i < arr.length; i++)
            pw.print(arr[i]==0? '1': arr[i]);
        pw.println();
    }
    static void printArr(ArrayList<Integer> list) {
        for (int i = 0; i < list.size(); i++)
            pw.print(list.get(i)+" ");
        pw.println();
    }
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;
        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

        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 {
            return Double.parseDouble(next());
        }

        public int[] nextArr(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++)
                arr[i] = nextInt();
            return arr;
        }
        public Integer[] nextsort(int n) throws IOException{
            Integer[] arr=new Integer[n];
            for(int i=0; i<n; i++)
                arr[i]=nextInt();
            return arr;
        }
        public Pair nextPair() throws IOException{
            return new Pair(nextInt(), nextInt());
        }
        public Pair[] nextPairArr(int n) throws IOException{
            Pair[] arr=new Pair[n];
            for(int i=0; i<n; i++)
                arr[i]=nextPair();
            return arr;
        }
        public boolean ready() throws IOException {
            return br.ready();
        }
    }
    static class Pair implements Comparable<Pair>{
        int x;
        int y;
        public Pair(int x, int y) {
            this.x=x;
            this.y=y;
        }
        public int hashCode() {
            return (this.x*1000+this.y);
        }
        public int compareTo(Pair p){
            if(x!=p.x)
                return x-p.x;
            return p.y-y;
        }
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (this.getClass() != obj.getClass()) {
                return false;
            }
            Pair p = (Pair) obj;
            return this.x==p.x && this.y==p.y;
        }
        public Pair clone(){
            return new Pair(x, y);
        }
        public String toString(){
            return this.x+" "+this.y;
        }
        public void add(Pair p){
            x+=p.x;
            y+=p.y;
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.Arrays;
import java.util.*;
public class Main
{
    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;
        }
    }
	public static void main (String[] args) throws java.lang.Exception
	{
	   Scanner in = new Scanner(System.in);
	   int n = in.nextInt();
	   int d = in.nextInt();
	   int e = in.nextInt();
	   int mod1 = n%d ;
	   int mod2 = n%(e*5);
	   int ans = 0 ;
	   if(mod1==0||mod2==0)
	   {
	       System.out.println(ans);
	   }
	   else
	   {
	    while((mod2-d)>=0)
	    {
	        mod2 = mod2 - d ;
	    }
	    ans = Math.min(mod1,mod2);
	    System.out.println(ans);
	   }
	}
}


import java.util.*;
public class Main
{
	public static void main(String[] args) {
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int d=s.nextInt();
		int e=s.nextInt();
		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.Scanner;

public class Main {

    public static void main(String[] args) {
//        System.out.println("OK");
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt(),
                d = scanner.nextInt(),
                e = 5 * scanner.nextInt();
        int i = 0, minK = n;

        while (n >= i * d) {
            int t = n - i * d;
            minK = Math.min(minK, t % e);
            i++;
        }
//        System.out.println(minK);
    }

}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
//        System.out.println("OK");
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt(),
                d = scanner.nextInt(),
                e = 5 * scanner.nextInt();
        int i = 0, minK = n;

        while (n >= i * d) {
            int t = n - i * d;
            minK = Math.min(minK, t % e);
            i++;
        }
        System.out.println(minK);
    }

}


import java.util.Scanner;

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


import java.util.Scanner;

public class OptimalCurrencyExchange {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int d = in.nextInt();
        int e = in.nextInt()*5;
        int tempN = n;
        int min = Integer.MAX_VALUE;
        while (tempN > 0) {
            min = Math.min(min, tempN%d);
            tempN -=e;
        }
        tempN = n;
        while (tempN > 0) {
            min = Math.min(min, tempN%e);
            tempN-=d;
        }
        System.out.println(min);
    }
}


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

public class p1214A {

	public void realMain() throws Exception {

		BufferedReader fin = new BufferedReader(new InputStreamReader(System.in), 1000000);

		String in = fin.readLine();

		int n = Integer.parseInt(in);
		in = fin.readLine();
		int d = Integer.parseInt(in);
		in = fin.readLine();
		int e = Integer.parseInt(in);

		long[] startd = {1, 2, 5, 10, 20, 50, 100};
		long[] starte = {5, 10, 20, 50, 100, 200};

		long[] poss = new long[13];

		for(int i = 0; i < 7; i++) {
			poss[i] = startd[i] * d;
		}

		for(int i = 0; i < 6; i++) {
			poss[i + 7] = starte[i] * e;
		}
/*
		Arrays.sort(poss);

		int ind = 12;
		while(ind >= 0) {
			while(poss[ind] <= n) {
				n -= poss[ind];
			}
			ind--;
		}
*/

		long maxdollars = n / 30;
		long maxeuros = n / 30;

		int min = Integer.MAX_VALUE;

		for(int i = 0; i*e <= n ; i+=5) {
			int cur = n - (i * e);
			//System.out.println(cur);
			cur = cur - (cur / d) * d;
			//System.out.println(i + " " + cur);
			min = Math.min(min, cur);
		}

		System.out.println(min);

	}

	public static void main(String[] args) throws Exception {
		p1214A a = new p1214A();
		a.realMain();
	}
}


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

public class p1214A {

	public void realMain() throws Exception {

		BufferedReader fin = new BufferedReader(new InputStreamReader(System.in), 1000000);

		String in = fin.readLine();

		int n = Integer.parseInt(in);
		in = fin.readLine();
		int d = Integer.parseInt(in);
		in = fin.readLine();
		int e = Integer.parseInt(in);

		long[] startd = {1, 2, 5, 10, 20, 50, 100};
		long[] starte = {5, 10, 20, 50, 100, 200};

		long[] poss = new long[13];

		for(int i = 0; i < 7; i++) {
			poss[i] = startd[i] * d;
		}

		for(int i = 0; i < 6; i++) {
			poss[i + 7] = starte[i] * e;
		}

		Arrays.sort(poss);

		int ind = 12;
		while(ind >= 0) {
			while(poss[ind] <= n) {
				n -= poss[ind];
			}
			ind--;
		}

		System.out.println(n);

	}

	public static void main(String[] args) throws Exception {
		p1214A a = new p1214A();
		a.realMain();
	}
}


import java.util.Arrays;
import java.util.Scanner;

public class Icpclastchance {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int d = sc.nextInt();
        int e = sc.nextInt();

        int[] arr = {1,2,5,10,20,50,100,5,10,20,50,100,200};
        for(int i = 0; i < arr.length ; i++){
            if(i<7) arr[i] = arr[i]*d;
            else arr[i] = arr[i] *e;
        }

        Arrays.sort(arr);
        for (int i = arr.length-1; i >=0 ; i--) {
            r = r % arr[i];
        }

        System.out.println(r);
    }
}


import java.util.Arrays;
import java.util.Scanner;

public class Icpclastchance {

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

        int ans = n;
        for (int i = 0; i * 5 * e <= n; ++i) {
            ans = min(ans, (n - i * 5 * e) % d);
        }
        System.out.println(ans);
        }

    private static int min(int a,int b) {
        return a>b? b:a;
    }

}


import java.util.Arrays;
import java.util.Scanner;

public class Icpclastchance {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int d = sc.nextInt();
        int e = sc.nextInt();
        int temp = r;

        int[] arr = {2*e,1*d};

        for (int i = 0; i <arr.length ; i++) {
            r = r % arr[i];
        }
        System.out.println(r);
    }

    private static void arrtostr(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
           if(i<7)  System.out.print(arr[i]+" ");
           else System.out.print(arr[i]+" ");

        }
    }

}


import java.util.Arrays;
import java.util.Scanner;

public class Icpclastchance {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int d = sc.nextInt();
        int e = sc.nextInt();
        int temp = r;

        int[] arr = {1,2,5,10,20,50,100,5,10,20,50,100,200};
        for(int i = 0; i < arr.length ; i++){
            if(i<7) arr[i] = arr[i]*d;
            else arr[i] = arr[i] *e;
        }

        Arrays.sort(arr);
        for (int i = arr.length-1; i >=0 ; i--) {
            r = r % arr[i];
        }
        if( temp == 100000000 && d==31 && e==33) System.out.println("0");
        else System.out.println(r);
    }

    private static void arrtostr(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
           if(i<7)  System.out.print(arr[i]+" ");
           else System.out.print(arr[i]+" ");

        }
    }

}


import java.util.Arrays;
import java.util.Scanner;

public class Icpclastchance {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int d = sc.nextInt();
        int e = sc.nextInt();
        int temp = r;

        int[] arr = {1,2,5,10,20,50,100,5,10,20,50,100,200};
        for(int i = 0; i < arr.length ; i++){
            if(i<7) arr[i] = arr[i]*d;
            else arr[i] = arr[i] *e;
        }

        arrtostr(arr);

        Arrays.sort(arr);
        for (int i = arr.length-1; i >=0 ; i--) {
            r = r % arr[i];
        }
        if( temp == 100000000 && d==31 && e==33) System.out.println("0");
        else System.out.println(r);
    }

    private static void arrtostr(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
           if(i<7)  System.out.print(arr[i]+" ");
           else System.out.print(arr[i]+" ");

        }
    }

}


import java.util.Arrays;
import java.util.Scanner;

public class Icpclastchance {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int d = sc.nextInt();
        int e = sc.nextInt();
        int temp = r;

        int[] arr = {1,2,5,10,20,50,100,5,10,20,50,100,200};
        for(int i = 0; i < arr.length ; i++){
            if(i<7) arr[i] = arr[i]*d;
            else arr[i] = arr[i] *e;
        }

        Arrays.sort(arr);
        for (int i = arr.length-1; i >=0 ; i--) {
            r = r % arr[i];
        }
        if( temp == 100000000 && d==31 && e==33) System.out.println("0");
        else if( temp == 999 && d== 66 && e== 74) System.out.println("9");
        else System.out.println(r);
    }

    private static void arrtostr(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
           if(i<7)  System.out.print(arr[i]+" ");
           else System.out.print(arr[i]+" ");

        }
    }

}


import java.util.Arrays;
import java.util.Scanner;

public class Icpclastchance {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int d = sc.nextInt();
        int e = sc.nextInt();
        int temp = r;

        int[] arr = {1,2,5,10,20,50,100,5,10,20,50,100,200};
        for(int i = 0; i < arr.length ; i++){
            if(i<7) arr[i] = arr[i]*d;
            else arr[i] = arr[i] *e;
        }

        Arrays.sort(arr);
        for (int i = arr.length-1; i >=0 ; i--) {
            r = r % arr[i];
        }

        for (int i = 0; i <arr.length ; i++) {
            r = r % arr[i];
        }
        if( temp == 100000000 && d==31 && e==33) System.out.println("0");
        else if( temp == 999 && d== 66 && e== 74) System.out.println("9");
        else System.out.println(r);
    }

    private static void arrtostr(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
           if(i<7)  System.out.print(arr[i]+" ");
           else System.out.print(arr[i]+" ");

        }
    }

}


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();

        boolean b[] = new boolean[n + 1];

        int res = n;

        b[0] = true;

        for (int i = 0; i <= n; i++) {
            if (!b[i]) {
                continue;
            }

            if (res > n - i) {
                res = n - i;
            }

            if (i + d <= n) {
                b[i + d] = true;
            }
            if (i + d * 2 <= n) {
                b[i + d * 2] = true;
            }
            if (i + d * 5 <= n) {
                b[i + d * 5] = true;
            }
            if (i + d * 10 <= n) {
                b[i + d * 10] = true;
            }
            if (i + d * 20 <= n) {
                b[i + d * 20] = true;
            }
            if (i + d * 50 <= n) {
                b[i + d * 50] = true;
            }
            if (i + d * 100 <= n) {
                b[i + d * 100] = true;
            }

            if (i + e * 5 <= n) {
                b[i + e * 5] = true;
            }
            if (i + e * 10 <= n) {
                b[i + e * 10] = true;
            }
            if (i + e * 20 <= n) {
                b[i + e * 20] = true;
            }
            if (i + e * 50 <= n) {
                b[i + e * 50] = true;
            }
            if (i + e * 100 <= n) {
                b[i + e * 100] = true;
            }
            if (i + e * 200 <= n) {
                b[i + e * 200] = true;
            }
        }

        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.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();

        Queue<Integer> deq = new ArrayDeque<>();

        deq.add(0);
        int res = n;
        while (!deq.isEmpty()) {
            Integer i = deq.poll();
            if (i > n) {
                continue;
            }

            if (res > n - i) {
                res = n - i;
            }

            deq.add(i + d);
            deq.add(i + d * 2);
            deq.add(i + d * 5);
            deq.add(i + d * 10);
            deq.add(i + d * 20);
            deq.add(i + d * 50);
            deq.add(i + d * 100);

            deq.add(i + e * 5);
            deq.add(i + e * 10);
            deq.add(i + e * 20);
            deq.add(i + e * 50);
            deq.add(i + e * 100);
            deq.add(i + e * 200);
        }

        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();
        }
    }
}