#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define MAX INT_MAX
#define MIN INT_MIN
#define MOD 1000000007
#define FO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
set <int> s;
bool ar[100001];
void seive() {
	ar[0] = ar[1] = true;

	for(int p=2; p*p<=100001; p++) {
		if(ar[p] == false) {
			for(int i=p*p;i<=100001;i+=p)
				ar[i] = true ;
		}
	}

	for(int p=2;p<=100001;p++) {
		if(ar[p] == false)
			s.insert(p);
	}
}
void solve() {
	int n, m;
	cin >> n >> m;
	int v[n] = {0};
	int flag = 0, flag2 = 0;
	for(int i=0;i<m;i++) {
		int x, y;
		cin >> x >> y;
		x--;
		if(v[x] == 0) {
			v[x] = y;
		}
		else {
			if(v[x] != y) {
				flag = 1;
			}
		}

	}
	int num = 0;
	for(int i=0;i<n;i++)
		num = num*10 + v[i];
	if(n != 1 && num == 0) {
		cout << "-1" << endl;
		return ;
	}
	if(flag == 1)
		cout << "-1" << endl;
	else {
			cout << num << endl;
	}
    return;
}
int32_t main() {
    FO;
    solve();
    return 0;
}