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];
}

int findMinMatch(int first, int last, const(int)[] ss, const(char)[] cs) {
	foreach (i;first..last) {
		auto s = i.to!string;
		auto matched = true;

		foreach (j;0..ss.length) {
			if (ss[j] >= s.length || s[ss[j]] != cs[j]) {
				matched = false;
			}
		}
		if (matched) return i;
	}
	return -1;
}

void main() {
	int n, m;
	int[] ss;
	char[] cs;
	
	readPair(n, m);

	foreach (i;0..m) {
		int s, c;
		readPair(s, c);
		ss ~= s - 1;
		cs ~= cast(char)c + '0';
	}

	switch (n) {
	case 3:
		findMinMatch(100, 1000, ss, cs).writeln;
		break;
	case 2:
		findMinMatch(10, 100, ss, cs).writeln;
		break;
	case 1:
		findMinMatch(0, 10, ss, cs).writeln;
		break;
	default:
		assert(false);
	}
}
