//“Make it work, make it right, make it fast.” – Kent Beck
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dd;
const int siz = 1e6 + 5;
const int MOD = 1e9 + 7;
#define endl '\n'
#define deb(x) cout << #x << " = " << x << endl;
void solve(){
	int n, m;
	cin >> n >> m;
	int s[m], c[m];
	for(int i = 0; i < m; i++)
		cin >> s[i] >> c[i];
	
	int a[n] = {0};
	for(int i= 0; i < m; i++){
		if(s[i] <= n){
		if(c[i] > a[s[i]-1])
			a[s[i]-1] = c[i];
		}
	}
	if(a[0] == 0)
		cout << -1 << endl;
	else{
		for(int &i : a)
			cout << i ;
		}
}

int main(){
	#ifndef RAY
		//freopen("input.txt", "r", stdin);
	#endif
		ios::sync_with_stdio(false);
		cin.tie(nullptr);
		int t = 1;
		//cin >> t;
		while(t--){
			solve();
		}
	return 0;
}
