#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  vector<int> Ans(N, 0);
  vector<int> zero(N, 0);
  int A = -2;
  for (int i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  for (int i = 0; i < M; i++) {
    if (N == 1 && c.at(i) == 0) {
      A = 0;
    } else if (s.at(i) == 1 && c.at(i) == 0) {
      A = -1;
    }
  }
  for (int i = 0; i < M; i++) {
    for (int j = i; j < M; j++) {
      if (s.at(i) == s.at(j) && c.at(i) != c.at(j)) {
        A = -1;
      }
    }
  }
  for (int i = 0; i < M; i++) {
    Ans.at(s.at(i) - 1) = c.at(i);
  }
  if (Ans == zero) {
    A = 0;
  }
  if (A == 0) {
    cout << A;
  } else if (A != -1) {
    if (Ans.at(0) == 0) {
      Ans.at(0) = 1;
    }
    for (int i = 0; i < N; i++) {
      cout << Ans.at(i);
    }
  } else {
    cout << A;
  }
  cout << endl;
}
