#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int n,m,sg=1;cin>>n>>m;int ls[n]={};
	while(m--){int a,b;
		cin>>a>>b;
		if(!ls[a-1]||ls[a-1]==b)ls[a-1]=b;
		else sg=0;
		}
	if(sg&&ls[0]!=0)for(int x:ls)cout<<x;
	else cout<<-1;
}

