/// RIFAT SHARIAR SAKIL
/// SOFTWARE ENGINEERING, SUST
/// 2019831024

#include<bits/stdc++.h>
#define ll long long
#define t INT_MAX
using namespace std;
int main()
{
    int n,m,i;
    cin >> n >> m;
    int a[n]={0},mx[3]={t,t,t};
    for(i=0;i<m;i++)
    {
        int s,c;
        cin >> s >> c;
        if( i && c<mx[s-1])
        {

            mx[s-1]= c;
            a[s-1] = c;
        }
        else if(c>0 && c<mx[s-1] )
        {
            mx[s-1] = c;
            a[s-1] = c;
        }
    }
    if(a[0]==0) cout << "-1\n";
    else
    {for(i=0;i<n;i++)cout << a[i];}
}
