It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh. In this game Mashmokh writes sequence of n distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first move he removes the first and the second integer from from the board, on the second move he removes the first and the second integer of the remaining sequence from the board, and so on. Bimokh stops when the board contains less than two numbers. When Bimokh removes numbers x and y from the board, he gets gcd(x, y) points. At the beginning of the game Bimokh has zero points.Mashmokh wants to win in the game. For this reason he wants his boss to get exactly k points in total. But the guy doesn't know how choose the initial sequence in the right way. Please, help him. Find n distinct integers a1, a2, ..., an such that his boss will score exactly k points. Also Mashmokh can't memorize too huge numbers. Therefore each of these integers must be at most 109.

The first line of input contains two space-separated integers n, k (1 ≤ n ≤ 105; 0 ≤ k ≤ 108).

If such sequence doesn't exist output -1 otherwise output n distinct space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).

Notegcd(x, y) is greatest common divisor of x and y.

;(function () {

	print(function (n, k) {

		var t = Math.floor(n/2);

		if (k < t) return -1;
		if (n === 1 && k !== 0) return -1;

		var result = [k - t + 1];
		if (result.length < n) result.push(result[0] * 2);
		while (result.length < n) result.push(result.slice(-1)[0] + 1);

		return result.join(' ');

	}.apply(null, readline().split(' ').map(Number)));

}.call(this));

function main(){
    var s = readline().split( ' ' ),
        n = s[0] - '',
        k = s[1] - '';

    if (k < Math.floor( n/2 ) || 1 === n && k > 0) {
        print( -1 );
    } else {
        var ans = [k - Math.floor( n/2 ) + 1];
        n > 1 && ans.push( ans[0] * 2 );
        for (var i=2; i<n; i++) {
            ans.push( 900000000 + i );
        }
        print( ans.join( ' ' ) );
    }
}
main();

function trim(s) {
    return s.replace(/^\s+|\s+$/gm, '');
}
function tokenize(s) {
    return trim(s).split(/\s+/);
}
function tokenizeIntegers(s) {
    var tokens = tokenize(s);
    for(var i=0; i<tokens.length; ++i) {
        tokens[i]=parseInt(tokens[i]);
    }
    return tokens;
}
function main() {
    var data = tokenizeIntegers(readline());
    var sequenceLength=data[0], totalScore=data[1];
    if(sequenceLength==1) {
        print(totalScore==0?1:-1);
        return;
    }
    if(Math.floor(sequenceLength/2)>totalScore) {
        print(-1);
        return;
    }
    var arr=[];
    var x=totalScore-Math.floor((sequenceLength-2)/2);
    arr[0]=x;
    arr[1]=x*2;
    for(var i=2; i<sequenceLength; ++i) {
        arr[i]=x*2+i;
    }
    print(arr.join(" "));
}
main();

function trim(s) {
    return s.replace(/^\s+|\s$/gm, '');
}
function tokenize(s) {
    return trim(s).split(/\s+/);
}
function integers(s) {
    var tokens=tokenize(s);
    for(var i=0; i<tokens.length; ++i) {
        tokens[i]=parseInt(tokens[i]);
    }
    return tokens;
}
function main() {
    var data = integers(readline());
    var n = data[0], k=data[1];
    if(n==1) {
        if(k==0) {
            print(1);
            return;
        } else {
            print(-1);
            return;
        }
    }
    if(k<Math.floor(n/2)) {
        print(-1);
        return;
    }
    var arr = [];
    var x = k - Math.floor((n-2)/2);
    arr[0]=x;
    arr[1]=x*2;
    for(var i=2; i<n; ++i) {
        arr[i]=x*2+i;
    }
    print(arr.join(" "));
}
main();

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function eratosthenes(max) {
	var mark = new Array(max+1);
	var primes = [];
	var pos = 1;
	while (true) {
		pos += 1;
		while (pos <= max && mark[pos]) {
			pos += 1;
		}
		if (pos > max) {
			break;
		}
		primes.push(pos);
		for (var seek = 2*pos; seek <= max; seek += pos) {
			mark[seek] = true;
		}
	}
	return primes;
}

function main() {
	var data = tokenizeIntegers(readline());
	var sequenceLength = data[0], totalScore = data[1];

	if (sequenceLength == 1) {
		print(totalScore == 0 ? 1 : -1);
		return;
	}

	if (Math.floor(sequenceLength/2) > totalScore) {
		print(-1);
		return;
	}

	var primes = eratosthenes(20000),
		numPrimes = primes.length;

	var numPairs = Math.floor(sequenceLength/2);
	var sequence = [];
	var rowA = 0, columnA = 0,
		rowB = Math.floor(numPrimes/2), columnB = rowB;

	function advance() {
		++columnA;
		++columnB;
		if (columnB == numPrimes) {
			++rowA;
			++rowB;
			columnA = rowA;
			columnB = rowB;
		}
	}

	var remainder = totalScore + 1 - numPairs;

	for (var pairIndex = numPairs-1; pairIndex > 0; --pairIndex) {
		while (true) {
			var a = primes[rowA]*primes[columnA];
			var b = primes[rowB]*primes[columnB];
			advance();
			if (a != remainder && a != 2*remainder &&
					b != remainder && b != 2*remainder) {
				break;
			}
		}
		sequence.push(a);
		sequence.push(b);
	}

	if (remainder > 0) {
		sequence.push(remainder);
		sequence.push(remainder*2);
	}

	if (sequenceLength % 2 == 1) {
		sequence.push(remainder == 3 ? 5 : 3);
	}

	print(sequence.join(" "));
}

main();

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function eratosthenes(max) {
	var mark = new Array(max+1);
	var primes = [];
	var pos = 1;
	while (true) {
		pos += 1;
		while (pos <= max && mark[pos]) {
			pos += 1;
		}
		if (pos > max) {
			break;
		}
		primes.push(pos);
		for (var seek = 2*pos; seek <= max; seek += pos) {
			mark[seek] = true;
		}
	}
	return primes;
}

function main() {
	var data = tokenizeIntegers(readline());
	var sequenceLength = data[0], totalScore = data[1];

	if (sequenceLength == 1) {
		print(totalScore == 0 ? 1 : -1);
		return;
	}

	if (Math.floor(sequenceLength/2) > totalScore) {
		print(-1);
		return;
	}

	var primes = eratosthenes(20000),
		numPrimes = primes.length;

	var numPairs = Math.floor(sequenceLength/2);
	var sequence = [], a = 2, b;
	var remainder = totalScore + 1 - numPairs;

	for (var pairIndex = numPairs-1; pairIndex > 0; --pairIndex) {
		while (true) {
			a += 2;
			b = a+1;
			if (a != remainder && a != 2*remainder &&
					b != remainder && b != 2*remainder) {
				break;
			}
		}
		sequence.push(a);
		sequence.push(b);
	}

	if (remainder > 0) {
		sequence.push(remainder);
		sequence.push(remainder*2);
	}

	if (sequenceLength % 2 == 1) {
		sequence.push(remainder == 3 ? 2 : 3);
	}

	print(sequence.join(" "));
}

main();

;(function () {

	print(function (n, k) {

		var t = Math.floor(n/2);

		if (k < t) return -1;

		var result = [k - t + 1]; result.push(result[0] * 2);
		while (result.length < n) result.push(result.slice(-1)[0] + 1);

		return result.join(' ');

	}.apply(null, readline().split(' ').map(Number)));

}.call(this));

;(function () {

	print(function (n, k) {

		var t = Math.floor(n/2);

		if (k < t) return -1;
		if (n === 1 && k !== 0) return -1;

		var result = [k - t + 1]; result.push(result[0] * 2);
		while (result.length < n) result.push(result.slice(-1)[0] + 1);

		return result.join(' ');

	}.apply(null, readline().split(' ').map(Number)));

}.call(this));

;(function () {

	print(function (n, k) {

		var t = Math.floor(n/2);

		if (k < t) return -1;

		var result = [k - t + 1, k - t + 1];
		while (result.length < n) result.push(1);

		return result.join(' ');

	}.apply(null, readline().split(' ').map(Number)));

}.call(this));

function trim(s) {
    return s.replace(/^\s+|\s$/gm, '');
}
function tokenize(s) {
    return trim(s).split(/\s+/);
}
function integers(s) {
    var tokens=tokenize(s);
    for(var i=0; i<tokens.length; ++i) {
        tokens[i]=parseInt(tokens[i]);
    }
    return tokens;
}
function main() {
    var data = integers(readline());
    var n = data[0], k=data[1];
    if(n==1) {
        if(k==0) {
            print(1);
            return;
        } else {
            print(-1);
            return;
        }
    }
    if(k<n/2) {
        print(-1);
        return;
    }
    var arr = [];
    var x = k - Math.floor((n-2)/2);
    arr[0]=x;
    arr[1]=x*2;
    for(var i=2; i<n; ++i) {
        arr[i]=x*2+i;
    }
    print(arr.join(" "));
}
main();

function trim(s) {
    return s.replace(/^\s+|\s+$/gm, '');
}
function tokenize(s) {
    return trim(s).split(/\s+/);
}
function tokenizeIntegers(s) {
    var tokens = tokenize(s);
    for(var i=0; i<tokens.length; ++i) {
        tokens[i]=parseInt(tokens[i]);
    }
    return tokens;
}
function main() {
    var data = tokenizeIntegers(readline());
    var sequenceLength=data[0], totalScore=data[1];
    if(sequenceLength==1) {
        print(totalScore==0?1:-1);
        return;
    }
    if(Math.floor(sequenceLength/2)>totalScore) {
        print(-1);
        return;
    }
    var arr=[];
    var x=totalScore-Math.floor((sequenceLength-2)/2);
    arr[0]=x;
    arr[1]=x*2;
    for(var i=2; i<sequenceLength; ++i) {
        arr[i]=x*2+i;
    }
    print(arr);
}
main();

function trim(s) {
    return s.replace(/^\s+|\s+$/gm, '');
}
function tokenize(s) {
    return trim(s).split(/\s+/);
}
function tokenizeIntegers(s) {
    var tokens = tokenize(s);
    for(var i=0; i<tokens.length; ++i) {
        tokens[i]=parseInt(tokens[i]);
    }
    return tokens;
}
function main() {
    var data = tokenizeIntegers(readline());
    var sequenceLength=data[0], totalScore=data[1];
    if(sequenceLength==1) {
        print(totalScore==0?1:-1);
        return;
    }
    if(Math.floor(sequenceLength/2)>totalScore) {
        print(-1);
        return;
    }
    var arr=[];
    var x=totalScore-(sequenceLength-2)/2;
    arr[0]=x;
    arr[1]=x*2;
    for(var i=2; i<sequenceLength; ++i) {
        arr[i]=x*2+i;
    }
    print(arr.join(" "));
}
main();

function trim(s) {
    return s.replace(/^\s+|\s+$/gm, '');
}
function tokenize(s) {
    return trim(s).split(/\s+/);
}
function tokenizeIntegers(s) {
    var tokens = tokenize(s);
    for(var i=0; i<tokens.length; ++i) {
        tokens[i]=parseInt(tokens[i]);
    }
    return tokens;
}
function main() {
    var data = tokenizeIntegers(readline());
    var sequenceLength=data[0], totalScore=data[1];
    if(sequenceLength==1) {
        print(totalScore==0?1:-1);
        return;
    }
    if(Math.floor(sequenceLength/2)>totalScore) {
        print(-1);
        return;
    }
    var x=totalScore-(sequenceLength-2)/2;
    print(x+ " " + x*2);
    for(var i=2; i<sequenceLength; ++i) {
        print(x*2+i + " ");
    }
}
main();

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function eratosthenes(max) {
	var mark = new Array(max+1);
	var primes = [];
	var pos = 1;
	while (true) {
		pos += 1;
		while (pos <= max && mark[pos]) {
			pos += 1;
		}
		if (pos > max) {
			break;
		}
		primes.push(pos);
		for (var seek = 2*pos; seek <= max; seek += pos) {
			mark[seek] = true;
		}
	}
	return primes;
}

function main() {
	var data = tokenizeIntegers(readline());
	var sequenceLength = data[0], totalScore = data[1];

	if (sequenceLength == 1) {
		print(totalScore == 0 ? 1 : -1);
		return;
	}

	if (Math.floor(sequenceLength/2) > totalScore) {
		print(-1);
		return;
	}

	var primes = eratosthenes(10000),
		numPrimes = primes.length;

	var numPairs = Math.floor(sequenceLength/2);
	var sequence = [];
	var rowA = 0, rowB = Math.floor(numPrimes/2),
		columnA = 0, columnB = numPrimes-1;

	function advance() {
		++columnA;
		--columnB;
		if (columnB <= columnA) {
			++rowA;
			++rowB;
			columnA = 0;
			columnB = numPrimes-1;
		}
	}

	var remainder = totalScore + 1 - numPairs;

	for (var pairIndex = numPairs-1; pairIndex > 0; --pairIndex) {
		while (true) {
			var a = primes[rowA]*primes[columnA];
			var b = primes[rowB]*primes[columnB];
			advance();
			if (a != remainder && a != 2*remainder &&
					b != remainder && b != 2*remainder) {
				break;
			}
		}
		sequence.push(a);
		sequence.push(b);
	}

	if (remainder > 0) {
		sequence.push(remainder);
		sequence.push(remainder*2);
	}

	if (sequenceLength % 2 == 1) {
		sequence.push(remainder == 3 ? 5 : 3);
	}

	print(sequence.join(" "));
}

main();

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function eratosthenes(max) {
	var mark = new Array(max+1);
	var primes = [];
	var pos = 1;
	while (true) {
		pos += 1;
		while (pos <= max && mark[pos]) {
			pos += 1;
		}
		if (pos > max) {
			break;
		}
		primes.push(pos);
		for (var seek = 2*pos; seek <= max; seek += pos) {
			mark[seek] = true;
		}
	}
	return primes;
}

function main() {
	var data = tokenizeIntegers(readline());
	var sequenceLength = data[0], totalScore = data[1];

	if (sequenceLength == 1) {
		print(totalScore == 0 ? 1 : -1);
		return;
	}

	if (Math.floor(sequenceLength/2) > totalScore) {
		print(-1);
		return;
	}

	var primes = eratosthenes(10000),
		numPrimes = primes.length;

	var numPairs = Math.floor(sequenceLength/2);
	var sequence = [];
	var row = 0, column = 0, oppositeColumn = numPairs-1;

	function advance() {
		++column;
		--oppositeColumn;
		if (oppositeColumn <= column) {
			row += 2;
			column = 0;
			oppositeColumn = numPairs-1;
		}
	}

	var remainder = totalScore + 1 - numPairs;

	for (var pairIndex = numPairs-1; pairIndex > 0; --pairIndex) {
		while (true) {
			var a = primes[row]*primes[column];
			var b = primes[row+1]*primes[oppositeColumn];
			if (a != remainder && a != 2*remainder &&
					b != remainder && b != 2*remainder) {
				break;
			}
			advance();
		}
		sequence.push(a);
		sequence.push(b);
	}

	if (remainder > 0) {
		sequence.push(remainder);
		sequence.push(remainder*2);
	}

	if (sequenceLength % 2 == 1) {
		sequence.push(remainder == 3 ? 5 : 3);
	}

	print(sequence.join(" "));
}

main();

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function eratosthenes(max) {
	var mark = new Array(max+1);
	var primes = [];
	var pos = 1;
	while (true) {
		pos += 1;
		while (pos <= max && mark[pos]) {
			pos += 1;
		}
		if (pos > max) {
			break;
		}
		primes.push(pos);
		for (var seek = 2*pos; seek <= max; seek += pos) {
			mark[seek] = true;
		}
	}
	return primes;
}

function main() {
	var data = tokenizeIntegers(readline());
	var sequenceLength = data[0], totalScore = data[1];

	if (Math.floor(sequenceLength/2) > totalScore) {
		print(-1);
		return;
	}

	var primes = eratosthenes(10000),
		numPrimes = primes.length;

	var numPairs = Math.floor(sequenceLength/2);
	var sequence = [];
	var row = 0, column = 0, oppositeColumn = numPairs-1;

	function advance() {
		++column;
		--oppositeColumn;
		if (oppositeColumn <= column) {
			row += 2;
			column = 0;
			oppositeColumn = numPairs-1;
		}
	}

	var remainder = totalScore + 1 - numPairs;

	for (var pairIndex = numPairs-1; pairIndex > 0; --pairIndex) {
		while (true) {
			var a = primes[row]*primes[column];
			var b = primes[row+1]*primes[oppositeColumn];
			if (a != remainder && a != 2*remainder &&
					b != remainder && b != 2*remainder) {
				break;
			}
			advance();
		}
		sequence.push(a);
		sequence.push(b);
	}

	if (remainder > 0) {
		sequence.push(remainder);
		sequence.push(remainder*2);
	}

	if (sequenceLength % 2 == 1) {
		sequence.push(remainder == 3 ? 5 : 3);
	}

	print(sequence.join(" "));
}

main();

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function eratosthenes(max) {
	var mark = new Array(max+1);
	var primes = [];
	var pos = 1;
	while (true) {
		pos += 1;
		while (pos <= max && mark[pos]) {
			pos += 1;
		}
		if (pos > max) {
			break;
		}
		primes.push(pos);
		for (var seek = 2*pos; seek <= max; seek += pos) {
			mark[seek] = true;
		}
	}
	return primes;
}

function main() {
	var data = tokenizeIntegers(readline());
	var sequenceLength = data[0], totalScore = data[1];

	if (Math.floor(sequenceLength/2) > totalScore) {
		print(-1);
		return;
	}

	var primes = eratosthenes(10000),
		numPrimes = primes.length;
	print(numPrimes);

	var numPairs = Math.floor(sequenceLength/2);
	var sequence = [];
	var row = 0, column = 0, oppositeColumn = numPairs-1;

	function advance() {
		++column;
		--oppositeColumn;
		if (oppositeColumn <= column) {
			row += 2;
			column = 0;
			oppositeColumn = numPairs-1;
		}
	}

	var remainder = totalScore + 1 - numPairs;

	for (var pairIndex = numPairs-1; pairIndex > 0; --pairIndex) {
		while (true) {
			var a = primes[row]*primes[column];
			var b = primes[row+1]*primes[oppositeColumn];
			if (a != remainder && a != 2*remainder &&
					b != remainder && b != 2*remainder) {
				break;
			}
			advance();
		}
		sequence.push(a);
		sequence.push(b);
	}

	if (remainder > 0) {
		sequence.push(remainder);
		sequence.push(remainder*2);
	}

	if (sequenceLength % 2 == 1) {
		sequence.push(remainder == 3 ? 5 : 3);
	}

	print(sequence.join(" "));
}

main();

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function eratosthenes(max) {
	var mark = new Array(max+1);
	var primes = [];
	var pos = 1;
	while (true) {
		pos += 1;
		while (pos <= max && mark[pos]) {
			pos += 1;
		}
		if (pos > max) {
			break;
		}
		primes.push(pos);
		for (var seek = 2*pos; seek <= max; seek += pos) {
			mark[seek] = true;
		}
	}
	return primes;
}

function main() {
	var data = tokenizeIntegers(readline());
	var sequenceLength = data[0], totalScore = data[1];

	if (sequenceLength == 1) {
		print(totalScore == 0 ? 1 : -1);
		return;
	}

	if (Math.floor(sequenceLength/2) > totalScore) {
		print(-1);
		return;
	}

	var primes = eratosthenes(20000),
		numPrimes = primes.length;

	var numPairs = Math.floor(sequenceLength/2);
	var sequence = [];
	var rowA = 0, rowB = Math.floor(numPrimes/2),
		columnA = 0, columnB = numPrimes-1;

	function advance() {
		++columnA;
		--columnB;
		if (columnB <= columnA) {
			++rowA;
			++rowB;
			columnA = rowA;
			columnB = numPrimes-1-rowA;
		}
	}

	var remainder = totalScore + 1 - numPairs;

	for (var pairIndex = numPairs-1; pairIndex > 0; --pairIndex) {
		while (true) {
			var a = primes[rowA]*primes[columnA];
			var b = primes[rowB]*primes[columnB];
			advance();
			if (a != remainder && a != 2*remainder &&
					b != remainder && b != 2*remainder) {
				break;
			}
		}
		sequence.push(a);
		sequence.push(b);
	}

	if (remainder > 0) {
		sequence.push(remainder);
		sequence.push(remainder*2);
	}

	if (sequenceLength % 2 == 1) {
		sequence.push(remainder == 3 ? 5 : 3);
	}

	print(sequence.join(" "));
}

main();

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function eratosthenes(max) {
	var mark = new Array(max+1);
	var primes = [];
	var pos = 1;
	while (true) {
		pos += 1;
		while (pos <= max && mark[pos]) {
			pos += 1;
		}
		if (pos > max) {
			break;
		}
		primes.push(pos);
		for (var seek = 2*pos; seek <= max; seek += pos) {
			mark[seek] = true;
		}
	}
	return primes;
}

function main() {
	var data = tokenizeIntegers(readline());
	var sequenceLength = data[0], totalScore = data[1];

	if (sequenceLength == 1) {
		print(totalScore == 0 ? 1 : -1);
		return;
	}

	if (Math.floor(sequenceLength/2) > totalScore) {
		print(-1);
		return;
	}

	var primes = eratosthenes(10000),
		numPrimes = primes.length;

	var numPairs = Math.floor(sequenceLength/2);
	var sequence = [];
	var row = 0, column = 0, oppositeColumn = numPrimes-1;

	function advance() {
		++column;
		--oppositeColumn;
		if (oppositeColumn <= column) {
			row += 2;
			column = 0;
			oppositeColumn = numPrimes-1;
		}
	}

	var remainder = totalScore + 1 - numPairs;

	for (var pairIndex = numPairs-1; pairIndex > 0; --pairIndex) {
		while (true) {
			var a = primes[row]*primes[column];
			var b = primes[row+1]*primes[oppositeColumn];
			advance();
			if (a != remainder && a != 2*remainder &&
					b != remainder && b != 2*remainder) {
				break;
			}
		}
		//print("row = "+row+", column = "+column+", oppositeColumn = "+
		//		oppositeColumn+", a = "+a+", b = "+b);
		sequence.push(a);
		sequence.push(b);
	}

	if (remainder > 0) {
		sequence.push(remainder);
		sequence.push(remainder*2);
	}

	if (sequenceLength % 2 == 1) {
		sequence.push(remainder == 3 ? 5 : 3);
	}

	print(sequence.join(" "));
}

main();

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function eratosthenes(max) {
	var mark = new Array(max+1);
	var primes = [];
	var pos = 1;
	while (true) {
		pos += 1;
		while (pos <= max && mark[pos]) {
			pos += 1;
		}
		if (pos > max) {
			break;
		}
		primes.push(pos);
		for (var seek = 2*pos; seek <= max; seek += pos) {
			mark[seek] = true;
		}
	}
	return primes;
}

function main() {
	var data = tokenizeIntegers(readline());
	var sequenceLength = data[0], totalScore = data[1];

	if (sequenceLength == 1) {
		print(totalScore == 0 ? 1 : -1);
		return;
	}

	if (Math.floor(sequenceLength/2) > totalScore) {
		print(-1);
		return;
	}

	var primes = eratosthenes(20000),
		numPrimes = primes.length;

	var numPairs = Math.floor(sequenceLength/2);
	var sequence = [];
	var rowA = 0, columnA = 0,
		rowB = Math.floor(numPrimes/2), columnB = rowB;

	function advance() {
		++columnA;
		++columnB;
		if (columnB <= columnA) {
			++rowA;
			++rowB;
			columnA = rowA;
			columnB = rowB;
		}
	}

	var remainder = totalScore + 1 - numPairs;

	for (var pairIndex = numPairs-1; pairIndex > 0; --pairIndex) {
		while (true) {
			var a = primes[rowA]*primes[columnA];
			var b = primes[rowB]*primes[columnB];
			advance();
			if (a != remainder && a != 2*remainder &&
					b != remainder && b != 2*remainder) {
				break;
			}
		}
		sequence.push(a);
		sequence.push(b);
	}

	if (remainder > 0) {
		sequence.push(remainder);
		sequence.push(remainder*2);
	}

	if (sequenceLength % 2 == 1) {
		sequence.push(remainder == 3 ? 5 : 3);
	}

	print(sequence.join(" "));
}

main();

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function eratosthenes(max) {
	var mark = new Array(max+1);
	var primes = [];
	var pos = 1;
	while (true) {
		pos += 1;
		while (pos <= max && mark[pos]) {
			pos += 1;
		}
		if (pos > max) {
			break;
		}
		primes.push(pos);
		for (var seek = 2*pos; seek <= max; seek += pos) {
			mark[seek] = true;
		}
	}
	return primes;
}

function main() {
	var data = tokenizeIntegers(readline());
	var sequenceLength = data[0], totalScore = data[1];

	if (sequenceLength == 1) {
		print(totalScore == 0 ? 1 : -1);
		return;
	}

	if (Math.floor(sequenceLength/2) > totalScore) {
		print(-1);
		return;
	}

	var primes = eratosthenes(10000),
		numPrimes = primes.length;

	var numPairs = Math.floor(sequenceLength/2);
	var sequence = [];
	var row = 0, column = 0, oppositeColumn = numPrimes-1;

	function advance() {
		++column;
		--oppositeColumn;
		if (oppositeColumn <= column) {
			row += 2;
			column = 0;
			oppositeColumn = numPrimes-1;
		}
	}

	var remainder = totalScore + 1 - numPairs;

	for (var pairIndex = numPairs-1; pairIndex > 0; --pairIndex) {
		while (true) {
			var a = primes[row]*primes[column];
			var b = primes[row+1]*primes[oppositeColumn];
			advance();
			if (a != remainder && a != 2*remainder &&
					b != remainder && b != 2*remainder) {
				break;
			}
		}
		print("row = "+row+", column = "+column+", oppositeColumn = "+
				oppositeColumn+", a = "+a+", b = "+b);
		sequence.push(a);
		sequence.push(b);
	}

	if (remainder > 0) {
		sequence.push(remainder);
		sequence.push(remainder*2);
	}

	if (sequenceLength % 2 == 1) {
		sequence.push(remainder == 3 ? 5 : 3);
	}

	print(sequence.join(" "));
}

main();

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function eratosthenes(max) {
	var mark = new Array(max+1);
	var primes = [];
	var pos = 1;
	while (true) {
		pos += 1;
		while (pos <= max && mark[pos]) {
			pos += 1;
		}
		if (pos > max) {
			break;
		}
		primes.push(pos);
		for (var seek = 2*pos; seek <= max; seek += pos) {
			mark[seek] = true;
		}
	}
	return primes;
}

function main() {
	var data = tokenizeIntegers(readline());
	var sequenceLength = data[0], totalScore = data[1];

	if (sequenceLength == 1 || Math.floor(sequenceLength/2) > totalScore) {
		print(-1);
		return;
	}

	var primes = eratosthenes(10000),
		numPrimes = primes.length;

	var numPairs = Math.floor(sequenceLength/2);
	var sequence = [];
	var row = 0, column = 0, oppositeColumn = numPairs-1;

	function advance() {
		++column;
		--oppositeColumn;
		if (oppositeColumn <= column) {
			row += 2;
			column = 0;
			oppositeColumn = numPairs-1;
		}
	}

	var remainder = totalScore + 1 - numPairs;

	for (var pairIndex = numPairs-1; pairIndex > 0; --pairIndex) {
		while (true) {
			var a = primes[row]*primes[column];
			var b = primes[row+1]*primes[oppositeColumn];
			if (a != remainder && a != 2*remainder &&
					b != remainder && b != 2*remainder) {
				break;
			}
			advance();
		}
		sequence.push(a);
		sequence.push(b);
	}

	if (remainder > 0) {
		sequence.push(remainder);
		sequence.push(remainder*2);
	}

	if (sequenceLength % 2 == 1) {
		sequence.push(remainder == 3 ? 5 : 3);
	}

	print(sequence.join(" "));
}

main();

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function eratosthenes(max) {
	var mark = new Array(max+1);
	var primes = [];
	var pos = 1;
	while (true) {
		pos += 1;
		while (pos <= max && mark[pos]) {
			pos += 1;
		}
		if (pos > max) {
			break;
		}
		primes.push(pos);
		for (var seek = 2*pos; seek <= max; seek += pos) {
			mark[seek] = true;
		}
	}
	return primes;
}

function main() {
	var data = tokenizeIntegers(readline());
	var sequenceLength = data[0], totalScore = data[1];

	if (sequenceLength == 1) {
		print(totalScore == 0 ? 1 : -1);
		return;
	}

	if (Math.floor(sequenceLength/2) > totalScore) {
		print(-1);
		return;
	}

	var primes = eratosthenes(20000),
		numPrimes = primes.length;

	var numPairs = Math.floor(sequenceLength/2);
	var sequence = [];
	var rowA = 0, rowB = Math.floor(numPrimes/2),
		columnA = 0, columnB = numPrimes-1;

	function advance() {
		++columnA;
		--columnB;
		if (columnB <= columnA) {
			++rowA;
			++rowB;
			columnA = rowA;
			columnB = numPrimes-1;
		}
	}

	var remainder = totalScore + 1 - numPairs;

	for (var pairIndex = numPairs-1; pairIndex > 0; --pairIndex) {
		while (true) {
			var a = primes[rowA]*primes[columnA];
			var b = primes[rowB]*primes[columnB];
			advance();
			if (a != remainder && a != 2*remainder &&
					b != remainder && b != 2*remainder) {
				break;
			}
		}
		sequence.push(a);
		sequence.push(b);
	}

	if (remainder > 0) {
		sequence.push(remainder);
		sequence.push(remainder*2);
	}

	if (sequenceLength % 2 == 1) {
		sequence.push(remainder == 3 ? 5 : 3);
	}

	print(sequence.join(" "));
}

main();


Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions:  $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty.  $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells.    These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$.

The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$.

NoteIn the first example, this is the other possible case.  In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$.

(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Queue = require('../queue');
var Stack = require('../stack');

var Graph = function () {
    function Graph() {
        var _this = this;

        var nodes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
        var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;

        _classCallCheck(this, Graph);

        this.directed = directed;
        this.nodes = nodes;
        this.edges = {};
        nodes.forEach(function (node) {
            _this.edges[node] = [];
        });
    }

    _createClass(Graph, [{
        key: 'addNode',
        value: function addNode(node) {
            // is it required ?
            if (this.edges[node]) {
                throw new Error('Graph.prototype.addNode: node is already exists');
                return;
            }

            this.nodes.push(node);
            this.edges[node] = [];
        }
    }, {
        key: 'addEdge',
        value: function addEdge(node1, node2) {
            var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;

            this.edges[node1].push({ node: node2, weight: weight });

            if (!this.directed) {
                this.edges[node2].push({ node: node1, weight: weight });
            }
        }
    }]);

    return Graph;
}();

module.exports = Graph;

},{"../queue":4,"../stack":5}],2:[function(require,module,exports){
"use strict";

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = function () {
    function Node(value) {
        _classCallCheck(this, Node);

        this.value = value;
        this.nextNode = null;
        this.prevNode = null;
    }

    _createClass(Node, [{
        key: "getValue",
        value: function getValue() {
            return this.value;
        }
    }, {
        key: "setValue",
        value: function setValue(value) {
            this.value = value;
        }
    }, {
        key: "setNext",
        value: function setNext(nextNodeLink) {
            this.nextNode = nextNodeLink;
        }
    }, {
        key: "setPrev",
        value: function setPrev(prevNodeLink) {
            this.prevNode = prevNodeLink;
        }
    }, {
        key: "getNext",
        value: function getNext() {
            return this.nextNode;
        }
    }, {
        key: "getPrev",
        value: function getPrev() {
            return this.prevNode;
        }
    }]);

    return Node;
}();

module.exports = Node;

},{}],3:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Queue = function () {
    function Queue() {
        _classCallCheck(this, Queue);

        this.firstItemLink = null;
        this.lastItemLink = null;
    }

    _createClass(Queue, [{
        key: 'enqueue',
        value: function enqueue(item, priority) {
            var node = new Node({
                item: item,
                priority: priority
            });

            if (this.isEmpty()) {
                this.lastItemLink = node;
                this.firstItemLink = node;
            } else {

                if (priority >= this.firstItemLink.getValue().priority) {
                    // Вперед
                    node.setNext(this.firstItemLink);
                    this.firstItemLink = node;
                } else if (priority <= this.lastItemLink.getValue().priority) {
                    // Назад
                    this.lastItemLink.setNext(node);
                    this.lastItemLink = node;
                } else {
                    // В середину
                    var currentNode = this.firstItemLink;
                    while (currentNode) {
                        var nextNode = currentNode.getNext();
                        if (priority >= nextNode.getValue().priority) {
                            currentNode.setNext(node);
                            node.setNext(nextNode);
                            currentNode = null;
                        } else {
                            currentNode = nextNode;
                        }
                    }
                }
            }
        }
    }, {
        key: 'dequeue',
        value: function dequeue() {
            if (this.isEmpty()) {
                return undefined;
            }

            if (this.lastItemLink === this.firstItemLink) {
                this.lastItemLink = null;
            }

            var firstItem = this.firstItemLink;

            this.firstItemLink = this.firstItemLink.getNext();

            return firstItem.getValue().item;
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.firstItemLink;
        }
    }]);

    return Queue;
}();

module.exports = Queue;

},{"../node":2}],4:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Queue = function () {
    function Queue() {
        _classCallCheck(this, Queue);

        this.firstItemLink = null;
        this.lastItemLink = null;
    }

    _createClass(Queue, [{
        key: 'enqueue',
        value: function enqueue(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.lastItemLink = node;
                this.firstItemLink = node;
            } else {
                this.lastItemLink.setNext(node);
                this.lastItemLink = node;
            }

            return node;
        }
    }, {
        key: 'dequeue',
        value: function dequeue() {
            if (this.isEmpty()) {
                return undefined;
            }

            if (this.lastItemLink === this.firstItemLink) {
                this.lastItemLink = null;
            }

            var firstItem = this.firstItemLink;

            this.firstItemLink = this.firstItemLink.getNext();

            return firstItem.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.firstItemLink;
        }
    }]);

    return Queue;
}();

module.exports = Queue;

},{"../node":2}],5:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Stack = function () {
    function Stack() {
        _classCallCheck(this, Stack);

        this.topItemLink = null;
    }

    _createClass(Stack, [{
        key: 'push',
        value: function push(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.topItemLink = node;
            } else {
                node.setPrev(this.topItemLink);
                this.topItemLink = node;
            }

            return node;
        }
    }, {
        key: 'pop',
        value: function pop() {
            if (this.isEmpty()) {
                return undefined;
            }

            var topItemLink = this.topItemLink;

            this.topItemLink = this.topItemLink.getPrev();

            return topItemLink.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.topItemLink;
        }
    }]);

    return Stack;
}();

module.exports = Stack;

},{"../node":2}],6:[function(require,module,exports){
'use strict';

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var Graph = require('../libs/graph');
var PriorityQueue = require('../libs/priority-queue');

var _readline$split$map = readline().split(' ').map(function (v) {
    return parseInt(v);
}),
    _readline$split$map2 = _slicedToArray(_readline$split$map, 2),
    h = _readline$split$map2[0],
    w = _readline$split$map2[1];

var table = [];
for (var i = 0; i < h; i++) {
    var row = [];
    for (var j = 0; j < w; j++) {
        row.push(-1);
    }
    table.push(row);
}

var r = readline().split(' ').map(function (v) {
    return parseInt(v);
});
var c = readline().split(' ').map(function (v) {
    return parseInt(v);
});

for (var _i = 0; _i < h; _i++) {

    if (r[_i] === 0) {
        table[_i][0] = 2; // белый
    } else {
        for (var _j = 0; _j < r[_i]; _j++) {
            table[_i][_j] = 1;
            table[_i][_j + 1] = 2;
        }
    }
}

var answer = -1;
for (var _i2 = 0; _i2 < w; _i2++) {
    // бежим по столбцам
    // console.log(i);
    if (c[_i2] === 0) {
        // значнеие столбца = 0 тогда первая клетка = 2;
        if (table[0][_i2] === 1) {
            answer = 0;
            break;
        }
        table[0][_i2] = 2;
    } else {
        // иначе начинаем бежать по всем строкам; номер столбца в данном случае = i а номер строки j =
        for (var _j2 = 0; _j2 < c[_i2]; _j2++) {
            if (table[_j2][_i2] === 2) {
                answer = 0;
                break;
            } else {
                table[_j2][_i2] = 1;
            }
        }

        if (table[c[_i2]]) {
            if (table[c[_i2]][_i2] === 1) {
                answer = 0;
                break;
            }
            table[c[_i2]][_i2] = 2;
        }
    }
}

//
// let answer =-1;
// for(let i = 0; i<c.length; i++) {
//     if (c[i] === 0) {
//        if(table[0][i] !== 2) {
//             answer = 0;
//             break
//        }
//     } else {
//         for(let j = 0; j<c[i]; j++) {
//             if (table[j][i] !== -1) {
//                 answer = 0;
//                 break;
//             }
//
//             table[j][i] = 1;
//         }
//
//         if(table[c[i]][i] === 1) {
//             answer = 0;
//             break;
//         } else {
//             table[c[i]][i] = 2;
//         }
//     }
// }
//
if (answer === 0) {
    write(0 + '\n');
} else {
    var a = 1;
    for (var _i3 = 0; _i3 < h; _i3++) {
        for (var _j3 = 0; _j3 < w; _j3++) {
            if (table[_i3][_j3] === -1) {
                a = a * 2 % 1000000007;
            }
        }
    }
    // console.log(table, h, w, a);
    write(a + '\n');
}

},{"../libs/graph":1,"../libs/priority-queue":3}]},{},[6]);

(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Queue = require('../queue');
var Stack = require('../stack');

var Graph = function () {
    function Graph() {
        var _this = this;

        var nodes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
        var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;

        _classCallCheck(this, Graph);

        this.directed = directed;
        this.nodes = nodes;
        this.edges = {};
        nodes.forEach(function (node) {
            _this.edges[node] = [];
        });
    }

    _createClass(Graph, [{
        key: 'addNode',
        value: function addNode(node) {
            // is it required ?
            if (this.edges[node]) {
                throw new Error('Graph.prototype.addNode: node is already exists');
                return;
            }

            this.nodes.push(node);
            this.edges[node] = [];
        }
    }, {
        key: 'addEdge',
        value: function addEdge(node1, node2) {
            var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;

            this.edges[node1].push({ node: node2, weight: weight });

            if (!this.directed) {
                this.edges[node2].push({ node: node1, weight: weight });
            }
        }
    }]);

    return Graph;
}();

module.exports = Graph;

},{"../queue":4,"../stack":5}],2:[function(require,module,exports){
"use strict";

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = function () {
    function Node(value) {
        _classCallCheck(this, Node);

        this.value = value;
        this.nextNode = null;
        this.prevNode = null;
    }

    _createClass(Node, [{
        key: "getValue",
        value: function getValue() {
            return this.value;
        }
    }, {
        key: "setValue",
        value: function setValue(value) {
            this.value = value;
        }
    }, {
        key: "setNext",
        value: function setNext(nextNodeLink) {
            this.nextNode = nextNodeLink;
        }
    }, {
        key: "setPrev",
        value: function setPrev(prevNodeLink) {
            this.prevNode = prevNodeLink;
        }
    }, {
        key: "getNext",
        value: function getNext() {
            return this.nextNode;
        }
    }, {
        key: "getPrev",
        value: function getPrev() {
            return this.prevNode;
        }
    }]);

    return Node;
}();

module.exports = Node;

},{}],3:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Queue = function () {
    function Queue() {
        _classCallCheck(this, Queue);

        this.firstItemLink = null;
        this.lastItemLink = null;
    }

    _createClass(Queue, [{
        key: 'enqueue',
        value: function enqueue(item, priority) {
            var node = new Node({
                item: item,
                priority: priority
            });

            if (this.isEmpty()) {
                this.lastItemLink = node;
                this.firstItemLink = node;
            } else {

                if (priority >= this.firstItemLink.getValue().priority) {
                    // Вперед
                    node.setNext(this.firstItemLink);
                    this.firstItemLink = node;
                } else if (priority <= this.lastItemLink.getValue().priority) {
                    // Назад
                    this.lastItemLink.setNext(node);
                    this.lastItemLink = node;
                } else {
                    // В середину
                    var currentNode = this.firstItemLink;
                    while (currentNode) {
                        var nextNode = currentNode.getNext();
                        if (priority >= nextNode.getValue().priority) {
                            currentNode.setNext(node);
                            node.setNext(nextNode);
                            currentNode = null;
                        } else {
                            currentNode = nextNode;
                        }
                    }
                }
            }
        }
    }, {
        key: 'dequeue',
        value: function dequeue() {
            if (this.isEmpty()) {
                return undefined;
            }

            if (this.lastItemLink === this.firstItemLink) {
                this.lastItemLink = null;
            }

            var firstItem = this.firstItemLink;

            this.firstItemLink = this.firstItemLink.getNext();

            return firstItem.getValue().item;
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.firstItemLink;
        }
    }]);

    return Queue;
}();

module.exports = Queue;

},{"../node":2}],4:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Queue = function () {
    function Queue() {
        _classCallCheck(this, Queue);

        this.firstItemLink = null;
        this.lastItemLink = null;
    }

    _createClass(Queue, [{
        key: 'enqueue',
        value: function enqueue(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.lastItemLink = node;
                this.firstItemLink = node;
            } else {
                this.lastItemLink.setNext(node);
                this.lastItemLink = node;
            }

            return node;
        }
    }, {
        key: 'dequeue',
        value: function dequeue() {
            if (this.isEmpty()) {
                return undefined;
            }

            if (this.lastItemLink === this.firstItemLink) {
                this.lastItemLink = null;
            }

            var firstItem = this.firstItemLink;

            this.firstItemLink = this.firstItemLink.getNext();

            return firstItem.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.firstItemLink;
        }
    }]);

    return Queue;
}();

module.exports = Queue;

},{"../node":2}],5:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Stack = function () {
    function Stack() {
        _classCallCheck(this, Stack);

        this.topItemLink = null;
    }

    _createClass(Stack, [{
        key: 'push',
        value: function push(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.topItemLink = node;
            } else {
                node.setPrev(this.topItemLink);
                this.topItemLink = node;
            }

            return node;
        }
    }, {
        key: 'pop',
        value: function pop() {
            if (this.isEmpty()) {
                return undefined;
            }

            var topItemLink = this.topItemLink;

            this.topItemLink = this.topItemLink.getPrev();

            return topItemLink.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.topItemLink;
        }
    }]);

    return Stack;
}();

module.exports = Stack;

},{"../node":2}],6:[function(require,module,exports){
'use strict';

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var Graph = require('../libs/graph');
var PriorityQueue = require('../libs/priority-queue');

var _readline$split$map = readline().split(' ').map(function (v) {
    return parseInt(v);
}),
    _readline$split$map2 = _slicedToArray(_readline$split$map, 2),
    h = _readline$split$map2[0],
    w = _readline$split$map2[1];

var table = [];
for (var i = 0; i < h; i++) {
    var row = [];
    for (var j = 0; j < w; j++) {
        row.push(-1);
    }
    table.push(row);
}

var r = readline().split(' ').map(function (v) {
    return parseInt(v);
});
var c = readline().split(' ').map(function (v) {
    return parseInt(v);
});

for (var _i = 0; _i < h; _i++) {

    if (r[_i] === 0) {
        table[_i][0] = 2; // белый
    } else {
        for (var _j = 0; _j < r[_i]; _j++) {
            table[_i][_j] = 1;
            table[_i][_j + 1] = 2;
        }
    }
}

var answer = -1;
for (var _i2 = 0; _i2 < w; _i2++) {
    // бежим по столбцам
    // console.log(i);
    if (c[_i2] === 0) {
        // значнеие столбца = 0 тогда первая клетка = 2;
        if (table[0][_i2] === 1) {
            answer = 0;
            break;
        }
        table[0][_i2] = 2;
    } else {
        // иначе начинаем бежать по всем строкам; номер столбца в данном случае = i а номер строки j =
        for (var _j2 = 0; _j2 < c[_i2]; _j2++) {
            if (table[_j2][_i2] === 2) {
                answer = 0;
                break;
            } else {
                table[_j2][_i2] = 1;
            }
        }

        if (c[_i2] < h) {
            if (table[c[_i2]][_i2] === 1) {
                answer = 0;
                break;
            }
            table[c[_i2]][_i2] = 2;
        }
    }
}

//
// let answer =-1;
// for(let i = 0; i<c.length; i++) {
//     if (c[i] === 0) {
//        if(table[0][i] !== 2) {
//             answer = 0;
//             break
//        }
//     } else {
//         for(let j = 0; j<c[i]; j++) {
//             if (table[j][i] !== -1) {
//                 answer = 0;
//                 break;
//             }
//
//             table[j][i] = 1;
//         }
//
//         if(table[c[i]][i] === 1) {
//             answer = 0;
//             break;
//         } else {
//             table[c[i]][i] = 2;
//         }
//     }
// }
//
if (answer === 0) {
    write(0 + '\n');
} else {
    var a = 0;
    for (var _i3 = 0; _i3 < h; _i3++) {
        for (var _j3 = 0; _j3 < w; _j3++) {
            if (table[_i3][_j3] === -1) {
                a++;
            }
        }
    }
    // console.log(table, h, w, a);
    write(parseInt(Math.pow(2, a) % 1000000007) + '\n');
}

},{"../libs/graph":1,"../libs/priority-queue":3}]},{},[6]);

(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Queue = require('../queue');
var Stack = require('../stack');

var Graph = function () {
    function Graph() {
        var _this = this;

        var nodes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
        var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;

        _classCallCheck(this, Graph);

        this.directed = directed;
        this.nodes = nodes;
        this.edges = {};
        nodes.forEach(function (node) {
            _this.edges[node] = [];
        });
    }

    _createClass(Graph, [{
        key: 'addNode',
        value: function addNode(node) {
            // is it required ?
            if (this.edges[node]) {
                throw new Error('Graph.prototype.addNode: node is already exists');
                return;
            }

            this.nodes.push(node);
            this.edges[node] = [];
        }
    }, {
        key: 'addEdge',
        value: function addEdge(node1, node2) {
            var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;

            this.edges[node1].push({ node: node2, weight: weight });

            if (!this.directed) {
                this.edges[node2].push({ node: node1, weight: weight });
            }
        }
    }]);

    return Graph;
}();

module.exports = Graph;

},{"../queue":4,"../stack":5}],2:[function(require,module,exports){
"use strict";

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = function () {
    function Node(value) {
        _classCallCheck(this, Node);

        this.value = value;
        this.nextNode = null;
        this.prevNode = null;
    }

    _createClass(Node, [{
        key: "getValue",
        value: function getValue() {
            return this.value;
        }
    }, {
        key: "setValue",
        value: function setValue(value) {
            this.value = value;
        }
    }, {
        key: "setNext",
        value: function setNext(nextNodeLink) {
            this.nextNode = nextNodeLink;
        }
    }, {
        key: "setPrev",
        value: function setPrev(prevNodeLink) {
            this.prevNode = prevNodeLink;
        }
    }, {
        key: "getNext",
        value: function getNext() {
            return this.nextNode;
        }
    }, {
        key: "getPrev",
        value: function getPrev() {
            return this.prevNode;
        }
    }]);

    return Node;
}();

module.exports = Node;

},{}],3:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Queue = function () {
    function Queue() {
        _classCallCheck(this, Queue);

        this.firstItemLink = null;
        this.lastItemLink = null;
    }

    _createClass(Queue, [{
        key: 'enqueue',
        value: function enqueue(item, priority) {
            var node = new Node({
                item: item,
                priority: priority
            });

            if (this.isEmpty()) {
                this.lastItemLink = node;
                this.firstItemLink = node;
            } else {

                if (priority >= this.firstItemLink.getValue().priority) {
                    // Вперед
                    node.setNext(this.firstItemLink);
                    this.firstItemLink = node;
                } else if (priority <= this.lastItemLink.getValue().priority) {
                    // Назад
                    this.lastItemLink.setNext(node);
                    this.lastItemLink = node;
                } else {
                    // В середину
                    var currentNode = this.firstItemLink;
                    while (currentNode) {
                        var nextNode = currentNode.getNext();
                        if (priority >= nextNode.getValue().priority) {
                            currentNode.setNext(node);
                            node.setNext(nextNode);
                            currentNode = null;
                        } else {
                            currentNode = nextNode;
                        }
                    }
                }
            }
        }
    }, {
        key: 'dequeue',
        value: function dequeue() {
            if (this.isEmpty()) {
                return undefined;
            }

            if (this.lastItemLink === this.firstItemLink) {
                this.lastItemLink = null;
            }

            var firstItem = this.firstItemLink;

            this.firstItemLink = this.firstItemLink.getNext();

            return firstItem.getValue().item;
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.firstItemLink;
        }
    }]);

    return Queue;
}();

module.exports = Queue;

},{"../node":2}],4:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Queue = function () {
    function Queue() {
        _classCallCheck(this, Queue);

        this.firstItemLink = null;
        this.lastItemLink = null;
    }

    _createClass(Queue, [{
        key: 'enqueue',
        value: function enqueue(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.lastItemLink = node;
                this.firstItemLink = node;
            } else {
                this.lastItemLink.setNext(node);
                this.lastItemLink = node;
            }

            return node;
        }
    }, {
        key: 'dequeue',
        value: function dequeue() {
            if (this.isEmpty()) {
                return undefined;
            }

            if (this.lastItemLink === this.firstItemLink) {
                this.lastItemLink = null;
            }

            var firstItem = this.firstItemLink;

            this.firstItemLink = this.firstItemLink.getNext();

            return firstItem.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.firstItemLink;
        }
    }]);

    return Queue;
}();

module.exports = Queue;

},{"../node":2}],5:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Stack = function () {
    function Stack() {
        _classCallCheck(this, Stack);

        this.topItemLink = null;
    }

    _createClass(Stack, [{
        key: 'push',
        value: function push(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.topItemLink = node;
            } else {
                node.setPrev(this.topItemLink);
                this.topItemLink = node;
            }

            return node;
        }
    }, {
        key: 'pop',
        value: function pop() {
            if (this.isEmpty()) {
                return undefined;
            }

            var topItemLink = this.topItemLink;

            this.topItemLink = this.topItemLink.getPrev();

            return topItemLink.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.topItemLink;
        }
    }]);

    return Stack;
}();

module.exports = Stack;

},{"../node":2}],6:[function(require,module,exports){
'use strict';

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var Graph = require('../libs/graph');
var PriorityQueue = require('../libs/priority-queue');

var _readline$split$map = readline().split(' ').map(function (v) {
    return parseInt(v);
}),
    _readline$split$map2 = _slicedToArray(_readline$split$map, 2),
    h = _readline$split$map2[0],
    w = _readline$split$map2[1];

var table = [];
for (var i = 0; i < h; i++) {
    var row = [];
    for (var j = 0; j < w; j++) {
        row.push(-1);
    }
    table.push(row);
}

var r = readline().split(' ').map(function (v) {
    return parseInt(v);
});
var c = readline().split(' ').map(function (v) {
    return parseInt(v);
});

for (var _i = 0; _i < h; _i++) {

    if (r[_i] === 0) {
        table[_i][0] = 2; // белый
    } else {
        for (var _j = 0; _j < r[_i]; _j++) {
            table[_i][_j] = 1;
            table[_i][_j + 1] = 2;
        }
    }
}

var answer = -1;
for (var _i2 = 0; _i2 < w; _i2++) {
    // бежим по столбцам
    // console.log(i);
    if (c[_i2] === 0) {
        // значнеие столбца = 0 тогда первая клетка = 2;
        if (table[0][_i2] === 1) {
            answer = 0;
            break;
        }
        table[0][_i2] = 2;
    } else {
        // иначе начинаем бежать по всему столбцу; номер столбца в данном случае = i а номер строки j
        for (var _j2 = 0; _j2 < c[_i2]; _j2++) {
            if (table[_j2][_i2] === 2) {
                answer = 0;
                break;
            } else {
                table[_j2][_i2] = 1;
            }
        }

        if (table[c[_i2]]) {
            if (table[c[_i2]][_i2] === 1) {
                answer = 0;
                break;
            }
            table[c[_i2]][_i2] = 2;
        }
    }
}

//
// let answer =-1;
// for(let i = 0; i<c.length; i++) {
//     if (c[i] === 0) {
//        if(table[0][i] !== 2) {
//             answer = 0;
//             break
//        }
//     } else {
//         for(let j = 0; j<c[i]; j++) {
//             if (table[j][i] !== -1) {
//                 answer = 0;
//                 break;
//             }
//
//             table[j][i] = 1;
//         }
//
//         if(table[c[i]][i] === 1) {
//             answer = 0;
//             break;
//         } else {
//             table[c[i]][i] = 2;
//         }
//     }
// }
//
if (answer === 0) {
    write(0 + '\n');
} else {
    var a = 0;
    for (var _i3 = 0; _i3 < h; _i3++) {
        for (var _j3 = 0; _j3 < w; _j3++) {
            if (table[_i3][_j3] === -1) {
                a++;
            }
        }
    }
    // console.log(table, h, w, a);
    write(parseInt(Math.pow(2, a) % 1000000007) + '\n');
}

},{"../libs/graph":1,"../libs/priority-queue":3}]},{},[6]);

(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Queue = require('../queue');
var Stack = require('../stack');

var Graph = function () {
    function Graph() {
        var _this = this;

        var nodes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
        var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;

        _classCallCheck(this, Graph);

        this.directed = directed;
        this.nodes = nodes;
        this.edges = {};
        nodes.forEach(function (node) {
            _this.edges[node] = [];
        });
    }

    _createClass(Graph, [{
        key: 'addNode',
        value: function addNode(node) {
            // is it required ?
            if (this.edges[node]) {
                throw new Error('Graph.prototype.addNode: node is already exists');
                return;
            }

            this.nodes.push(node);
            this.edges[node] = [];
        }
    }, {
        key: 'addEdge',
        value: function addEdge(node1, node2) {
            var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;

            this.edges[node1].push({ node: node2, weight: weight });

            if (!this.directed) {
                this.edges[node2].push({ node: node1, weight: weight });
            }
        }
    }]);

    return Graph;
}();

module.exports = Graph;

},{"../queue":4,"../stack":5}],2:[function(require,module,exports){
"use strict";

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = function () {
    function Node(value) {
        _classCallCheck(this, Node);

        this.value = value;
        this.nextNode = null;
        this.prevNode = null;
    }

    _createClass(Node, [{
        key: "getValue",
        value: function getValue() {
            return this.value;
        }
    }, {
        key: "setValue",
        value: function setValue(value) {
            this.value = value;
        }
    }, {
        key: "setNext",
        value: function setNext(nextNodeLink) {
            this.nextNode = nextNodeLink;
        }
    }, {
        key: "setPrev",
        value: function setPrev(prevNodeLink) {
            this.prevNode = prevNodeLink;
        }
    }, {
        key: "getNext",
        value: function getNext() {
            return this.nextNode;
        }
    }, {
        key: "getPrev",
        value: function getPrev() {
            return this.prevNode;
        }
    }]);

    return Node;
}();

module.exports = Node;

},{}],3:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Queue = function () {
    function Queue() {
        _classCallCheck(this, Queue);

        this.firstItemLink = null;
        this.lastItemLink = null;
    }

    _createClass(Queue, [{
        key: 'enqueue',
        value: function enqueue(item, priority) {
            var node = new Node({
                item: item,
                priority: priority
            });

            if (this.isEmpty()) {
                this.lastItemLink = node;
                this.firstItemLink = node;
            } else {

                if (priority >= this.firstItemLink.getValue().priority) {
                    // Вперед
                    node.setNext(this.firstItemLink);
                    this.firstItemLink = node;
                } else if (priority <= this.lastItemLink.getValue().priority) {
                    // Назад
                    this.lastItemLink.setNext(node);
                    this.lastItemLink = node;
                } else {
                    // В середину
                    var currentNode = this.firstItemLink;
                    while (currentNode) {
                        var nextNode = currentNode.getNext();
                        if (priority >= nextNode.getValue().priority) {
                            currentNode.setNext(node);
                            node.setNext(nextNode);
                            currentNode = null;
                        } else {
                            currentNode = nextNode;
                        }
                    }
                }
            }
        }
    }, {
        key: 'dequeue',
        value: function dequeue() {
            if (this.isEmpty()) {
                return undefined;
            }

            if (this.lastItemLink === this.firstItemLink) {
                this.lastItemLink = null;
            }

            var firstItem = this.firstItemLink;

            this.firstItemLink = this.firstItemLink.getNext();

            return firstItem.getValue().item;
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.firstItemLink;
        }
    }]);

    return Queue;
}();

module.exports = Queue;

},{"../node":2}],4:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Queue = function () {
    function Queue() {
        _classCallCheck(this, Queue);

        this.firstItemLink = null;
        this.lastItemLink = null;
    }

    _createClass(Queue, [{
        key: 'enqueue',
        value: function enqueue(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.lastItemLink = node;
                this.firstItemLink = node;
            } else {
                this.lastItemLink.setNext(node);
                this.lastItemLink = node;
            }

            return node;
        }
    }, {
        key: 'dequeue',
        value: function dequeue() {
            if (this.isEmpty()) {
                return undefined;
            }

            if (this.lastItemLink === this.firstItemLink) {
                this.lastItemLink = null;
            }

            var firstItem = this.firstItemLink;

            this.firstItemLink = this.firstItemLink.getNext();

            return firstItem.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.firstItemLink;
        }
    }]);

    return Queue;
}();

module.exports = Queue;

},{"../node":2}],5:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Stack = function () {
    function Stack() {
        _classCallCheck(this, Stack);

        this.topItemLink = null;
    }

    _createClass(Stack, [{
        key: 'push',
        value: function push(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.topItemLink = node;
            } else {
                node.setPrev(this.topItemLink);
                this.topItemLink = node;
            }

            return node;
        }
    }, {
        key: 'pop',
        value: function pop() {
            if (this.isEmpty()) {
                return undefined;
            }

            var topItemLink = this.topItemLink;

            this.topItemLink = this.topItemLink.getPrev();

            return topItemLink.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.topItemLink;
        }
    }]);

    return Stack;
}();

module.exports = Stack;

},{"../node":2}],6:[function(require,module,exports){
'use strict';

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var Graph = require('../libs/graph');
var PriorityQueue = require('../libs/priority-queue');

var _readline$split$map = readline().split(' ').map(function (v) {
    return parseInt(v);
}),
    _readline$split$map2 = _slicedToArray(_readline$split$map, 2),
    h = _readline$split$map2[0],
    w = _readline$split$map2[1];

var table = [];
for (var i = 0; i < h; i++) {
    var row = [];
    for (var j = 0; j < w; j++) {
        row.push(-1);
    }
    table.push(row);
}

var r = readline().split(' ').map(function (v) {
    return parseInt(v);
});
var c = readline().split(' ').map(function (v) {
    return parseInt(v);
});

for (var _i = 0; _i < h; _i++) {

    if (r[_i] === 0) {
        table[_i][0] = 2; // белый
    } else {
        for (var _j = 0; _j < r[_i]; _j++) {
            table[_i][_j] = 1;
            table[_i][_j + 1] = 2;
        }
    }
}

var answer = -1;
for (var _i2 = 0; _i2 < w; _i2++) {
    // бежим по столбцам
    // console.log(i);
    if (c[_i2] === 0) {
        // значнеие столбца = 0 тогда первая клетка = 2;
        if (table[0][_i2] === 1) {
            answer = 0;
            break;
        }
        table[0][_i2] = 2;
    } else {
        // иначе начинаем бежать по всему столбцу; номер столбца в данном случае = i а номер строки j
        for (var _j2 = 0; _j2 < c[_i2]; _j2++) {
            if (table[_j2][_i2] === 2) {
                answer = 0;
                break;
            } else {
                table[_j2][_i2] = 1;
            }
        }

        if (table[c[_i2]]) {
            if (table[c[_i2]][_i2] === 1) {
                answer = 0;
                break;
            }
            table[c[_i2]][_i2] = 2;
        }
    }
}

//
// let answer =-1;
// for(let i = 0; i<c.length; i++) {
//     if (c[i] === 0) {
//        if(table[0][i] !== 2) {
//             answer = 0;
//             break
//        }
//     } else {
//         for(let j = 0; j<c[i]; j++) {
//             if (table[j][i] !== -1) {
//                 answer = 0;
//                 break;
//             }
//
//             table[j][i] = 1;
//         }
//
//         if(table[c[i]][i] === 1) {
//             answer = 0;
//             break;
//         } else {
//             table[c[i]][i] = 2;
//         }
//     }
// }
//
if (answer = 0) {
    write(0 + '\n');
} else {
    var a = 0;
    for (var _i3 = 0; _i3 < h; _i3++) {
        for (var _j3 = 0; _j3 < w; _j3++) {
            if (table[_i3][_j3] === -1) {
                a++;
            }
        }
    }
    // console.log(table, h, w, a);
    write(parseInt(Math.pow(2, a) % 1000000007) + '\n');
}

},{"../libs/graph":1,"../libs/priority-queue":3}]},{},[6]);


A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.

The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.

Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.