#include using namespace std; #define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define ALL(v) (v).begin(),(v).end() using ll=long long int; const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12; templateinline bool chmax(T& a,T b){if(ainline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;} struct UnionFind{ vector par; int n; UnionFind(){} UnionFind(int _n):par(_n,-1),n(_n){} int root(int x){return par[x]<0?x:par[x]=root(par[x]);} bool same(int x,int y){return root(x)==root(y);} int size(int x){return -par[root(x)];} bool unite(int x,int y){ x=root(x),y=root(y); if(x==y)return false; if(size(x)>size(y))swap(x,y); par[y]+=par[x]; par[x]=y; n--; return true; } }; using P=pair; P cnt[10002]; bitset<5002> dp[5002]; int rui[5002][5002]; int main(){ int n,m; cin>>n>>m; UnionFind uni(n*2); rep(i,0,m){ int x,y; cin>>x>>y; x--; y--; uni.unite(x,y+n); } int X=0,Y=0; rep(i,0,n){ if(uni.size(i)==1)X++; else cnt[uni.root(i)].first++; } rep(i,n,n*2){ if(uni.size(i)==1)Y++; else cnt[uni.root(i)].second++; } dp[0][0]=1; rep(x,0,n*2)if(cnt[x].first!=0 or cnt[x].second!=0){ auto [a,b]=cnt[x]; for(int i=n-a;i>=0;i--)dp[i+a]|=dp[i]<