#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <cmath>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cstdio>

using namespace std;
using ll = long long;
using ull = unsigned long long;


#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a-1;i>=b;i--)

auto sumdig(ll num) {
	ll dig, sum;
	sum = 0;
	while (num) {
		dig = num % 10;
		sum = sum + dig;
		num = num / 10;
	}
	return sum;
}




int main() {

	int n, m;
	int ans=0;
	cin >> n >> m;
	vector<int> sc(n,-1);
	bool cannot = false;
	rep(i, 0, m) {
		int ts, tc;
		cin >> ts >> tc;
		if (sc[ts - 1] == -1) {
			sc[ts - 1] = tc;
		}
		else if(sc[ts-1] != tc) {
			cannot = true;
		}

		
	}
	if (cannot) {
		cout << "-1" << endl;
		return 0;
	}
	if (n != 0 && sc[0] == 0) {
		cout << -1 << endl;
		return 0;
	}

	rep(i, 0, n-1) {
		if (sc[i] != -1) {
			ans += pow(10, n-1-i)*sc[i];
		}
		else if (sc[0] == -1 && i==0) {
			ans += pow(10, n - 1 - i);
		}
		else {
			ans += 0;
		}
	}
	
	if (sc[n - 1] != -1) {
		ans += sc[n - 1];
	}



	cout << ans << endl;
	return 0;
}