#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;

	int* s = new int[m];
	int* c = new int[m];

	for (int i = 0; i < m; i++) {
		cin >> s[i] >> c[i];
	}


	int answer = -1;
	bool flag;
	for (int i = 0; i < 1000; i++) {
		flag = true;
		for (int j = 0; j < m; j++) {
			int a;
			switch (s[j])
			{
			case 1:
				if (c[j] != (int)(i / 100)) {
					flag = false;
				}
				break;
			case 2:
				if (c[j] != ((int)(i / 10) % 10)) {
					flag = false;
				}
				break;
			case 3:
				if (c[j] != i % 10) {
					flag = false;
				}
				break;
			default:
				break;
			}
		}
		if (flag) {
			answer = i;
			break;
		}
	}

	if ((answer * 10 / o) <= 0) {
		answer = -1;
	}

	cout << answer;

	return 0;
}