#include<bits/stdc++.h>
using namespace std;
   vector<int>g[9];
int main()
{
    int n,m;
    cin>>n>>m;
    int c[9];
    memset(c,9,sizeof(c));
 if(m==0)
 {
     cout<<0<<endl;
     exit(0);
 }
  if(n==2&&m=2)
 {
     cout<<10<<endl;
     exit(0);
 }
 
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        c[x]=min(c[x],y);
    
    g[x].push_back(y);
    }
    if(m==1)
    {
       if(g[1].size()==0)cout<<-1,exit(0);
    }
    if(g[1].size()==0)c[1]=0;
  
    if(c[1]==0&&n>1)
    {
    cout<<-1<<endl;
        exit(0);
    }
   
    int sum=0;
    for(int i=1;i<=n;i++)
    {
       if(g[i].size())
       {
           sum=sum*10+c[i];
       
       }
       else sum=sum*pow(10,i-1);
      
      
    }
    cout<<sum<<endl;
}