#include using namespace std; typedef pair pii; const int MAXK = 1000; const int INF = 1<<30; // 2 ^ 30 pii inp[MAXK+10]; int a[MAXK+10]; int d[MAXK+10][MAXK+10]; int main() { ios::sync_with_stdio(false); int k; cin >> k; for(int i=0; i> inp[i].first >> inp[i].second; for(int i=1; i= k ) break; int j = i+len; d[i][j] = INF; for(int m=i; m