//#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#define FOR(N) for(int i=0;i<N;i++)
#define FOR2(N) for(int j=0;j<N;j++)
using namespace std;
typedef long long ll;


int main() {
	int N;
	cin >> N;
	vector<int>A(N, -1);
	int M;
	cin >> M;
	int s[M] = { 0 };
	int c[M] = { 0 };
	FOR(M) {
		cin >> s[i] >> c[i];
	}
	FOR(M) {
		if ((A.at(s[i] - 1) != -1&&A.at(s[i]-1)!=c[s[i]-1]) || (s[i] == 1 && c[i] == 0)) {
			cout << -1 << endl;
			return 0;
		}
		A.at(s[i] - 1) = c[i];

	}
	FOR(M) {
		if (A.at(i) == -1) {
			if (i == 0)
				cout << 1;
			else
				cout << 0;
		}
		else
			cout << A.at(i);
	}
	cout << endl;
}
