#include using namespace std; typedef long long ll; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b #define vl vector #define vii vector> #define vll vector> #define vvi vector> #define vvl vector> #define vvii vector>> #define vvll vector>> #define vst vector #define pii pair #define pll pair #define pb push_back #define all(x) (x).begin(),(x).end() #define mkunique(x) sort(all(x));(x).erase(unique(all(x)),(x).end()) #define fi first #define se second #define mp make_pair #define si(x) int(x.size()) const int mod=998244353,MAX=5005,INF=15<<26; int mi[MAX*2][MAX],ma[MAX*2][MAX]; struct UF{ int n; vector par,size,edge,X,Y; void init(int n_){ n=n_; par.assign(n,-1); size.assign(n,1); edge.assign(n,0); X.assign(n,0); Y.assign(n,0); for(int i=0;i>N>>M; UF uf;uf.init(2*N); for(int i=0;i>a>>b;a--;b--; uf.unite(a,N+b); } vii S; for(int i=0;i<2*N;i++){ if(uf.root(i)==i){ int a=uf.X[i],b=uf.Y[i]; //cout<=0){ chmin(mi[i+1][j+a],ma[i][j]+b); chmax(ma[i+1][j+a],ma[i][j]+b); } } } int ans=INF; for(int a=0;a<=N;a++){ //cout<