#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,M;
    cin>>N>>M;
    int a[N]={};
    int b[N]={};
    int A,t,q,counter=0;
   for(int i=0;i<M;i++){
   cin>>A>>t;
   if(A==1&&t==0){
   counter++;
   break;}
   else if(b[A-1]==0){
   a[A-1]=t;
   b[A-1]++;}
   else {
   if(a[A-1]==t){
   continue;}
   else{
   counter++;
   break;}}}
   if(N==1&&M==0){
   cout<<0;}
   else if(counter==0){
   if(a[0]==0)
   a[0]=1;
   for(int i=0;i<N;i++){
   cout<<a[i];}}
   else
   cout<<-1<<endl;}
   
