#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

int main() {
    ll n,t,l,i,a,b; cin>>n>>t;
    map<ll,ll>m; ll s[n+1]={0};
    while(t--)
    {
        cin>>a>>b;
        if (m[a]>0&&m[a]!=b) {cout<<-1; return 0;}
        m[a]=b; s[a]=1;
    }
    ll d=m[1];
    for(i=2;i<=n;i++) {d=d*10+m[i];}
    if (d==0&&n>1) {cout<<-1;} else {cout<<d;}
	return 0;
}