import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;

T[] readNumbers(T)() {
	return readln.chomp.split(" ").map!(to!T).array;
}

void readPair(T)(out T a, out T b) {
	auto xs = readNumbers!T;
	a = xs[0];
	b = xs[1];
}

void main() {
	int n, m;
	readPair(n, m);

	if (m == 0) {
		writeln("0");
		return;
	}
	
	char[3] answer = "   ";
	
	foreach (i;0..m) {
		auto line = readln.chomp;
		int s = line[0] - '0' - 1;
		char c = line[2];

		if (answer[s] == ' ') {
			answer[s] = c;
		} else if (answer[s] != c) {
			writeln("-1");
			return;
		}
	}

	if (answer == "  0") {
		writeln("0");
		return;
	}

	switch (n) {
	case 1:
		if (answer[0..2] != "  ") {
			writeln("-1");
			return;
		} else {
			writeln(answer[2]);
			return;
		}
	case 2:
		if (answer[0] != ' ' || answer[1] == '0') {
			writeln("-1");
			return;
		}
		write(answer[1] == ' ' ? '1' : answer[1]);
		writeln(answer[2] == ' ' ? '0' : answer[2]);
		break;
	case 3:
		if (answer[0] == '0') {
			writeln("-1");
			return;
		}
		write(answer[0] == ' ' ? '1' : answer[0]);
		write(answer[1] == ' ' ? '0' : answer[1]);
		writeln(answer[2] == ' ' ? '0' : answer[2]);
		break;
	default:
		assert(false);
	}
}
