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 figures, times;
	readPair(figures, times);

	int[3] restriction = [-1, -1, -1];
	auto answer = 0;
 
	foreach (i;0..times) {
		int fromLeft, c;
		readPair(fromLeft, c);
		--fromLeft;

		if (restriction[fromLeft] == -1) {
			restriction[fromLeft] = c;
		} else if (restriction[fromLeft] != c) {
			answer = -1;
		}
	}

	switch (figures) {
	case 3:
		if (restriction[0] == -1) {
			restriction[0] = 1;
		}
		if (restriction[0] == 0) {
			answer = -1;
		}
		break;
	case 2:
		if (restriction[0] != -1 || restriction[1] == 0) {
			answer = -1;
		}
		if (restriction[1] == -1) {
			restriction[1] = 1;
		}
		break;
	case 1:
		if (restriction[0] != -1 || restriction[1] != -1) {
			answer = -1;
		}
		break;
	default:
	}

	if (answer == -1) {
		writeln("-1");
		return;
	}

	foreach (ref e;restriction) {
		if (e == -1) {
			e = 0;
		}
	}

	writeln(restriction[0] * 100 + restriction[1] * 10 + restriction[2]);
}
