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

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<pair<int ,int>> P(N);
  for (int i = 0; i < M; i++){
    cin >> P[i].first >> P[i].second;
  }
  
  int n1 = -1;
  int n2 = -1;
  int n3 = -1;
  int r = -1;
  if(N == 3){
    for (int i = 0; i < M; i++){
      if(P[i].first == 1){
        // N>1の場合に、一番上の桁が0  
        if(P[i].second == 0){
          cout << r << endl;
          return 0;
        }
        // 同じ桁で数字が違う
        if(n1 != -1 && n1 != P[i].second){
          cout << r << endl;
          return 0;
        }
        n1 = P[i].second;
      }
      if(P[i].first == 2){
        // 同じ桁で数字が違う
        if(n2 != -1 && n2 != P[i].second){
          cout << r << endl;
          return 0;
        }
        n2 = P[i].second;
      }
      if(P[i].first == 3){
        // 同じ桁で数字が違う
        if(n3 != -1 && n3 != P[i].second){
          cout << r << endl;
          return 0;
        }
        n3 = P[i].second;
      }
    }
    if (n1 == 0} {
      cout << r << endl;
      return 0;      
    }
    r = n1 * 100;
    if (n2 == -1) n2 = 0; 
    r += n2 * 10;
    if (n3 == -1) n3 = 0; 
    r += n3;
  }
  else if(N == 2){
    for (int i = 0; i < M; i++){
      if(P[i].first == 1){
        // N>1の場合に、一番上の桁が0  
        if(P[i].second == 0){
          cout << r << endl;
          return 0;
        }
        // 同じ桁で数字が違う
        if(n1 != -1 && n1 != P[i].second){
          cout << r << endl;
          return 0;
        }
        n1 = P[i].second;
      }
      if(P[i].first == 2){
        // 同じ桁で数字が違う
        if(n2 != -1 && n2 != P[i].second){
          cout << r << endl;
          return 0;
        }
        n2 = P[i].second;
      }
      if(P[i].first == 3){
        // 存在しない桁
        cout << r << endl;
        return 0;
      }
    }
    if (n1 == 0} {
      cout << r << endl;
      return 0;      
    }
    r = n1 * 10;
    if (n2 == -1) n2 = 0; 
    r += n2;
  }
  else {
    for (int i = 0; i < M; i++){
      if(P[i].first == 1){
        // 同じ桁で数字が違う
        if(n1 != -1 && n1 != P[i].second){
          cout << r << endl;
          return 0;
        }
        n1 = P[i].second;
      }
      if(P[i].first == 2){
        // 存在しない桁
        cout << r << endl;
        return 0;
      }
      if(P[i].first == 3){
        // 存在しない桁
        cout << r << endl;
        return 0;
      }
    }
    r = n1;
  }

  cout << r << endl;
}

