#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);
		}
	}
	bool non_zero = false;
	REP(i, 0, n){
		if(arr[i] != 0) non_zero = true;
	}
	
	if(non_zero || m==0){
		non_zero = false;
		REP(i, 0, n){
			if(arr[i] != 0) non_zero = true;
			
			if(non_zero) cout << arr[i];
			else{
				cout << 1;
				non_zero = true;
			}
		}
	}
	else cout << (n==1?0:-1);
}
