#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define mod 1000000007 
#define check exit(0)
#define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define trace(x) cerr<<#x<<" : "<<x<<endl;
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace __gnu_pbds;
using namespace std;

int main()
{
    jaldi
    int n,m;
    cin>>n>>m;
    vector<int> v(n,-1);
    for(int i=0;i<m;i++)
    {
        int l,d;
        cin>>l>>d;
        if(d==0 && l==1 && n!=1)
        {
            cout<<-1;
            return 0;
        }
        if(v[l-1]==-1) v[l-1]=d;
        else if(v[l-1]==d) continue;
        else
        {
            cout<<-1;
            return 0;
        }
    }
    for(int x:v) 
    {
        x!=-1?cout<<x:cout<<0;
    }
    return 0;
}
