#include <iostream>
#include <vector>

using namespace std;

int main(void) {
	int N, M, inputs, inputc, ans = 0;
	int checkNum = 0;
	vector<int> s;
	vector<int> c;
	cin >> N >> M;
	vector<vector<int>> sc(N, vector<int>(10, 0));
	for (int i = 0; i < M; i++) {
		cin >> inputs;
		s.emplace_back(inputs);
		cin >> inputc;
		c.emplace_back(inputc);
		sc[inputs - 1][inputc]++;
	}
	if (M == 1 && c[0] == 0) {
		ans = -1;
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 10; j++) {
			if (sc[i][j] >= 1) {
				checkNum++;
			}
		}
		if (checkNum > 1) {
			ans = -1;
			break;
		}
		else {
			checkNum = 0;
		}
	}
	if (ans != -1) {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < 10; j++) {
				if (sc[i][j] >= 1) {
					ans += j * pow(10, 3 - i - 1);
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}