#include using namespace std; typedef long long ll; typedef pair p_ll; template void debug(T itr1, T itr2) { auto now = itr1; while(now=0; i--) #define popcount __builtin_popcount const ll LLINF = pow(2,61)-1; const ll INF = pow(2,30)-1; ll gcd(ll a, ll b) { if (a> N >> M; vector A(N); rep(i,N) cin >> A[i]; vector B(M); rep(i,M) cin >> B[i]; assert(1<=N && N<=200000); assert(1<=M && M<=200000); rep(i,N) assert(1<=A[i] && A[i]<=1000000000 && (i==0||A[i-1] s; rep(i,N) s.insert(A[i]); rep(i,M) s.insert(B[i]); assert(s.size()==N+M); vector v; v.push_back(make_pair(-1*LLINF, 0)); v.push_back(make_pair(LLINF, 0)); rep(i,N) v.push_back(make_pair(A[i],0)); rep(i,M) v.push_back(make_pair(B[i],1)); sort(all(v)); ll result = 2*LLINF+1 - (N+2), m = 0; rep(i,N+M+1) { m = max(m, v[i+1].first-v[i].first-1); if (v[i+1].second==0) { result -= m; m = 0; } } cout << result << endl; return 0; }