#include #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #define FOR(i,n) for(int i = 0; i < (n); i++) #define sz(c) ((int)(c).size()) #define ten(x) ((int)1e##x) #define all(v) (v).begin(), (v).end() using namespace std; using ll=long long; using FLOW=int; using P = pair; const long double PI=acos(-1); const ll INF=1e18; const int inf=1e9; template struct SegmentTree{ using F=function; F fT; const T et; int n; vector dat; SegmentTree(int N,F fT_,T et_) : fT(fT_),et(et_){ n=1; while(n ll { return min(x1,x2); }; const ll e=INF; int main(){ int n; cin>>n; map> mp; for(int i=0;i>r; mp[r].insert(i+1); } SegmentTree dp(n+1,f,e); dp.update(1,0); for(int i=1;i<=n;i++){ for(auto l : mp[i]){ dp.apply(i,dp.query(l,i)+1); } } cout<