//Radhe Radhe
#include<bits/stdc++.h>//157B
#define ll long long
#define fixed cout.setf(ios::fixed);
#define rep1    for( i=0; i<n; i++)
#define Precise cout.precision(7);
using namespace std;

int main()
{
    ll n,i,j,m;
    cin>>n>>m;
    ll a[n]= {0},x,y;
    bool ok=1;
    for(i=0; i<m; i++)
    {
        cin>>x>>y;
        if(a[x-1]==y||a[x-1]==0)
        {
            a[x-1]=y;
        }
        else
        {
            ok=0;
        }
    }
    if(ok&&a[0]!=0)
    {
    for(i=0; i<n; i++)
    cout<<a[i];
    }
    else
    return cout<<-1<<endl,0;

    return 0;
}



