//by Top1
#include <bits/stdc++.h>
          
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define cerr cout
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
      
const int inf = (1e9) + 1;
const int mod = 479001599;
const int maxn = 1e6 + 111;
        
using namespace std;          

int n, m, a[maxn];

void solve(){ 
	cin >> n >> m;

	for (int i = 1; i <= n; i++)
		a[i] = inf;

	for (int i = 1; i <= m; i++){
		int x, y;
		cin >> x >> y;
		if (a[x] == inf)
			a[x] = y;
		else if (a[x] != y){
			cout << -1;
			return;
		}
	}
	
	for (int i = 1; i <= n; i++)
		if (a[i] == inf)
			a[i] = 0;

	if (n == 1){
		cout << 0;
		return;
	}
	if (n >= 2 && a[1] == 0){
		cout << -1;
		return;
	}

	for (int i = 1; i <= n; i++){
		cout << a[i];
	}
}                              
      
main(){
    boost;
    
    int q = 1;
 
    //cin >> q;
    
    while (q--){
        solve();
    }
}