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

int main() {
  int N, M;
  int s[N];
  int c[N];
  int out = 0;
  int d[N] = {};

  cin >> N >> M;
  for(int i=0;i<M;i++){
    cin >> s[i] >> c[i];

    if(s[i] == 1 && c[i] == 0){
      out = -1;
    }
  }

  for(int i=0;i<M;i++){
    for(int j=0;j<M;j++){
      if(i != j){
        if(s[i] == s[j] && c[i] != c[j]){
          out = -1;
        }
      }
    }
  }

  if(out == -1){
    cout << -1;
  }else{
    for(int i=0;i<M;i++){
      d[s[i] - 1] = pow(10, (N-s[i])) * c[i];
    }
    if(d[0] == 0 && N > 1){
      d[0] = 100;
    }
    cout << d[0] + d[1] + d[2];
  }


}