#include using namespace std; typedef long long ll; #define pb push_back #define fi first #define se second typedef pair P; using VP = vector

; using VVP = vector; using VI = vector; using VVI = vector; using VVVI = vector; const int inf=1e9+7; const ll INF=1LL<<60; const ll Mod=998244353; const ll MAX_V=400*400; int V; vector G[MAX_V]; vector rG[MAX_V]; vector vs; bool used[MAX_V]; int cmp[MAX_V]; void addedge(int from,int to){ G[from].push_back(to); rG[to].push_back(from); } void dfs(int v){ used[v]=true; for(int i=0;i=0;i--){ if(!used[vs[i]]) rdfs(vs[i],k++); } return k; } int main(){ int i,j; int h,w; cin>>h>>w; V=h*w; int a[h],b[w]; for(i=0;i>a[i]; for(i=0;i>b[i]; sort(a,a+h); sort(b,b+w); for(i=0;i