#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimization_level 3
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main(){
	ll n;
	ll m;
	cin>>n>>m;
	vector<ll> s(m);
	vector<ll> c(m);
	vector<ll> ans(n,0);

	rep(i,m){
		cin>>s.at(i)>>c.at(i);
	}

	int test = 345;
	ans.at(0)=1;

	
	
	for (size_t i = 0; i < m; i++)
	{
		if (ans.at(s.at(i)-1)==0 || ans.at(s.at(i)-1)==c.at(i) || ((s.at(i)-1)==0 && ans.at(s.at(i)-1)==1))
		{
			ans.at(s.at(i)-1) = c.at(i);
		} else {
			cout<<-1;
			return 0;
		}
		
	}


	if (n>1 && ans.at(0)==0)
	{
		cout<<-1;
		return 0;
	}

	// ll res = 0;
	// for (size_t i = 0; i < n; i++)
	// {
		// res += ans.at(i)*pow(10,n-i-1);
	// }

	// cout<<res;
	
	for (size_t i = 0; i < n; i++)
	{
		cout<<ans.at(i);
	}
	
	
}
