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