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