//#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,M;
	cin >> N>>M;
	int s[M] = { 0 };
	int c[M] = { 0 };
	vector<int>A(N, -1);
	FOR(M) {
		cin >> s[i] >> c[i];
		s[i]--;
	}
	FOR(M) {
		if (A[s[i]] != -1 && c[i] != A[s[i]]) {
			cout << -1 << endl;
			return 0;
		}
		A[s[i]] = c[i];
	}
	if (A[0] == 0) {
		cout << -1 << endl;
		return 0;
	}
	FOR(N) {
		if (i == 0 && A[0] == -1) {
			cout << 1;
		}
		else if (A[i] == -1)
			cout << 0;
		else
		cout << A[i];
	}
	cout << endl;
}
