#include <bits/stdc++.h>
using namespace std;

int main(){

  int N,M;
  cin >> N >> M;

  vector<int> s(M);
  vector<int> c(M);

  for (int i = 0; i < M; i++) {
   cin >> s.at(i);
   cin >> c.at(i);
  }

  int X1=0;
  int X2=0;
  int X3=0;

  int count=0;
  for (int i = 0; i < M; i++) {
    if (s.at(i)==1 && c.at(i)==0) count=-1;
  }

  vector<int> A(5);
  A.at(1)=-1;
  A.at(2)=-1;
  A.at(3)=-1;
  int Z;
  for (int i = 0; i < M; i++) {
    Z=s.at(i);
    if (A.at(Z)==-1) A.at(Z)=c.at(i);
    else{
      if (A.at(Z)!=c.at(i)) count=-1;
    }
  }

  if (M==0) count=-1;

  for (int i = 0; i < M; i++) {
    if (s.at(i)==1 && X1==0 && count!=-1) {
      if (N==1) count+=c.at(i);
      else if(N==2) count+=10*c.at(i);
      else if(N==3) count+=100*c.at(i);
      X1=1;
    }
    else if(s.at(i)==2 && X2==0 &&  count!=-1){
      if (N==1) count=-1;
      else if(N==2) count+=c.at(i);
      else if(N==3) count+=10*c.at(i);
      X2=1;
    }
    else if(s.at(i)==3 && X3==0 &&  count!=-1){
      if (N==1) count=-1;
      else if(N==2) count=-1;
      else if(N==3) count+=c.at(i);
      X3=1;
    }
    if (count==-1) break;
  }

  if (count!=-1){

    int sum=0
    int ncm=count;
    while (ncm>0){
      sum+=1;
      ncm/=10;
    }

    if (N==2 && sum==1){
      count+=10;
    }
    else if (N==3 && sum==1){
      count+=100;
    }
    else if (N==3 && sum==2){
      count+=100;
    }

  }

  cout << count << endl;
}