#include <iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
const int N = 205000;
const int inf = 0x3f3f3f3f;
int dist[N];
bool st[N];
//链表表示记得开大数组
int h[N], e[N], ne[N], idx, w[N];
//链接是连在头上,头插
void add(int a, int b, int c) {
ne[idx] = h[a], e[idx] = b, w[idx] = c, h[a] = idx++;
}
int gcd(int a, int b) {
return !b ? a : gcd(b, a % b);
}
int lcm(int x, int y) {
return x * y / gcd(x, y);
}
int SPFA() {
queue<int> q;
dist[1] = 0;
//这里的st数组代表的是这个点是否在队列中
st[1] = true;
q.push(1);
while (q.size()) {
int u = q.front();
q.pop();
st[u] = false;
//更新
for (int i = h[u]; i != -1; i = ne[i]) {
int t = e[i];
if (dist[t] > dist[u] + w[i]) {
dist[t] = dist[u] + w[i];
//更新就加进去
if (!st[t]) {
q.push(t);
st[t] = true;
}
}
}
}
return dist[2021];
}
int main()
{
memset(dist, inf, sizeof dist);
memset(w, inf, sizeof w);
//链表表示记得memset H数组
memset(h, -1, sizeof h);
for (int i = 1; i <= 2021; i++) {
for (int j = i + 1; j <= i + 21; j++) {
add(i, j, lcm(i, j));
//add(j,i,lcm(i,j));
}
}
cout << SPFA() << endl;
return 0;
}