#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N;
  cin >> N;
  int M;
  cin >> M;
  
  int count;
  count = 0;
  int s[M-1],c[M-1];
  while(count < M){
    cin >> s[count] >> c[count];
    count++;
  }
  int answer;
  int x,y,z;
  x = 0;
  y = 0;
  z = 0;
  for(int i = 0; i < M; i++){
    s[i] = N-s[i]+1;
    if (s[i] == 1)
      z = c[i];
    else if(s[i] == 2)
      y = c[i];
    else if(s[i] ==3)
      x = c[i];
  }
    for(int i =0; i < M; i++){
    for(int j = 0; j < M; j++){ 
      if((s[i] == s[j]){
        if(s[i] == 1)
          z = min(c[i],c[j]) ;
        else if(s[i] == 2)
          y = min(c[i],c[j]) ;
        else if(s[i] == 3)
          x = min(c[i],c[j]);
      }
         
    }
  }
  
  
  answer = x*100 + y*10 + z; 
  for(int i = 0; i < M ; i++){
	if((s[i] == 1) && (c[i] == 0))
      answer = -1;
  }
  for(int i =0; i < M; i++){
    for(int j = 0; j < M; j++){ 
      if((s[i] == s[j]) && (c[i] != c[j]))
         answer = -1;
    }
  }        
}