#include <iostream>
#include <vector>
#include <algorithm>

int main(){
	unsigned w, h;
	std::cin >> w >> h;
	std::vector<unsigned> a(w), b(h);
	for(unsigned &i : a) std::cin >> i;
	for(unsigned &i : b) std::cin >> i;

	std::sort(std::begin(a), std::end(a), std::greater<unsigned>());

	for(unsigned i : a){
		std::sort(std::begin(b), std::end(b), std::greater<unsigned>());
		for(unsigned j = 0; j < i; ++j){
			if(b[j]) --b[j];
			else{
				std::cout << '0' << std::endl;
				return 0;
			}
		}
	}
	for(unsigned i : b){
		if(i){
			std::cout << '0' << std::endl;
			return 0;
		}
	}
	std::cout << '1' << std::endl;
}

