#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  const int INF = 9999;
  int N, M;
  cin >> N >> M;
  vector<int> value(3, INF);
  rep(i, M){
    int s
    char c;
    cin >> s >> c;
    if(value.at(3-s) == INF || value.at(3-s) == c){
      value.at(3-s) = c;
    }
    else{
      cout << -1 << endl;
      return 0;
    }
  }
  for(int i = N; i < 3; ++i){
    if(value.at(i) != INF){
      cout << -1 << endl;
      return 0;
    }
  }
  if(value.at(N-1) == 0){
    cout << -1 << endl;
    return 0;
  }
  if(value.at(N-1) == INF){
    value.at(N-1) = 1;
  }
  rep(i,N-1){
    if(value.at(i)==INF){
      value.at(i) = 0;
    }
  }
  cout << value.at(0) + value.at(1)*10 + value.at(2)*100 << endl;
  return 0;
}