#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define dbl double
#define pi acos(-1)
#define sc1(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld%lld",&a,&b)
#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define pb push_back

priority_queue<ll>pq;
ll ara[1000006];
ll p[100005];
map<ll,ll>vis;

int main()
{
    ll n,m,c=0;
    sc2(n,m);
    for(ll i=1; i<=m; i++)
    {
        ll a,b;
        sc2(a,b);
        if(vis[a]!=0 && vis[a]!=b)
        {
            c++;
        }
        if(c==0)
        {
            vis[a]=b;
        }
    }
    if(c==0)
    {
            if(vis[1]==0 && n!=1)
            {
                cout<<"-1"<<endl;
                return 0;
            }
        for(ll i=1; i<=n; i++)
        {
            cout<<vis[i];
        }

        cout<<endl;
    }
    else
        cout<<"-1"<<endl;
    return 0;
}
