#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main() {
  int N,M;
  cin >> N >> M;
  vector<int>A(M);
  vector<int>B(M);
  rep(i,M){
    cin >> A[i] >> B[i];
  }
  if(N == 1){
    cout << A[0];
  }
  rep(i,M){
    if(N == 1){
      cout << A[0];
      return 0;
    for(int j = 1; j + i < M; j++){
      if(A[i] == A[i + j] && B[i] != B[j]){
        cout << "-1";
        return 0;
      }
    }
  }
  vector<int>C(N);
  rep(i,N){
    C[A[i] - 1] = B[i];
  }
  if(C[N - 1] == 0){
    cout << "-1";
    return 0;
  }
  if(C[0] == 0){
    cout << "0";
    return 0;
  }
  rep(i,N){
    cout << C[i];
  }
}