#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define d  long double
//#define d long double
#define pii pair<int,int>
#define pb push_back
#define N 200003
#define inf (int)1e18
#define haha ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

 
signed main()
{
    haha
   int n,m1;
   cin>>n>>m1;
   int f=0;
   map<int,int> m;
   int arr[n];
   memset(arr,0,sizeof(arr));
   int p=0;
   set<int> s;
   if(m==0 && n==1)
   {
       cout<<0;
       return 0;
   }
   if(m==0 && n>1)
   {
       cout<<-1;
       return 0;
   }
   for(int i=0;i<m1;i++)
   {
       int x,y;
       cin>>x>>y;
       if(x==1 && y==0 && n>1)
       f=1;
       if(x==1)
       p=1;
       if(s.find(x)!=s.end())
       {
           if(m[x]!=y)
           f=1;
       }
       else
       {
       m[x]=y;
       s.insert(x);
       }
       arr[x-1]=y;
   }
   if(p==0)
   f=1;
   if(f==1)
   cout<<-1;
   else
   {
       int x=0;
       for(int i=n-1;i>=0;i--)
       {
           x+=arr[i]*pow(10,(n-1-i));
       }
      cout<<x;
   }
   
    
    
}
