#include <bits/stdc++.h>
using namespace std;

int main() {
	int n, m, s, c;
	int num[3] = { 0 };
	vector<bool> check(3, true);
	bool out = false;

	cin >> n >> m;
	if (n == 3)num[2] = 1;
	if (n == 2)num[1] = 1;

	for (int i = 0; i < m; i++) {
		cin >> s >> c;
		if (n >=2 && s == 1 && c == 0)out = true;
		if (check.at(n - s) || num[n - s] == c) {
			num[n - s] = c;
			check.at(n - s) = false;
		}else out = true;
	}

	
	if (!out)cout << 100 * num[2] + 10 * num[1] + num[0] << endl;
	else cout << -1 << endl;
}
