import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class A {
public static void main(String[] args) throws IOException {
FastReader reader = new FastReader();
PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));
int n = reader.nextInt();
int a = reader.nextInt();
int b = reader.nextInt();
reader.close();
writer.println(solve(n, a, b));
writer.flush();
writer.close();
}
public static int solve(int n, int a, int b) {
return Math.max(n % a, n % b);
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
void close() {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
br = null;
st = null;
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
String nextLine() {
String str = "";
if (st.hasMoreElements()) {
str = st.nextToken("\n");
} else {
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
}
return str;
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
}
}