#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	int n, m;
	cin >> n >> m;
	int arr[n] = {0};
	int s, c;
	REP(i, 0, m){
		cin >> s >> c;
		if(arr[s-1] == 0 || arr[s-1] == c) arr[s-1] = c;
		else{
			cout << -1;
			exit(0);
		}
	}
	if(n == 1) cout << arr[0];
	else{
		REP(i, 0, n){
			if(i == 0 && arr[i] == 0) cout << 1;
			else cout << arr[i];
		}
	}
}
