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