#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pii pair<int,int>
#define ff first
#define ss second

void solve()
{
    int n,m;
    cin>>n>>m;
    string s(n,'0');
    bool vis[n+1]={0};
    for(int i=0;i<m;i++)
    {
        int a;
        char b;
        cin>>a>>b;
        a--;
        if(vis[a]&&s.at(a)!=b)
        {
            cout<<-1<<endl;
            exit(0);
        }
        else
        {
            s.at(a)=b;
        }
    }
    int count=0;
//    cout<<s.at(0)<<endl;
    while(count<s.size()&&s.at(count)=='0'&&s.size()!=1)
        count++;
    if(count>0)
    {
        cout<<-1<<endl;
        exit(0);
    }
    else
        cout<<s<<endl;
}

int main()
{

    int t;
    t = 1;
//    cin>>t;
    while(t--)
    {
        solve();
    }

}
