#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int w,h;
  cin>>w>>h;
  vector<Int> a(w),b(h);
  for(Int i=0;i<w;i++) cin>>a[i];
  for(Int i=0;i<h;i++) cin>>b[i];
  sort(a.rbegin(),a.rend());
  for(Int x:a){
    sort(b.rbegin(),b.rend());
    for(Int i=0;i<x;i++) b[i]--;
    if(*min_element(b.begin(),b.end())<0){
      cout<<0<<endl;
      return 0;
    }
  }
  cout<<(*max_element(b.begin(),b.end())==0)<<endl;
  return 0;
}

