#include <bits/stdc++.h>
using namespace std;
int main() {
  int i;
  int N, M;
  int s, c;
  cin >> N >> M;
  bool *cng = new bool[N];
  int *ans = new int[N];
  for (i = 0; i < N; i++) {
    cng[i] = false;
    ans[i] = -1;
  }
  for (i = 0; i < M; i++) {
    cin >> s >> c;
    s--;
    if (i == 0) {
      ans[s] = c;
      cng[s] = true;
    } else {
      if (!cng[s] || ans[s] == c) {
        ans[s] = c;
        cng[s] = true;
      } else {
        ans[s] = -1;
      }
    }
  }
  int tmp = 0;
  for (i = 0; i < N; i++) {
    tmp += ans[i];
  }
  if (tmp == -3) {
    cout << -1 << endl;
  } else if (N > 1 && ans[0] == 0) {
    cout << -1 << endl;
  } else {
    for (i = 0; i < N; i++) {
      if (ans[i] < 0) {
        ans[i] = 0;
      }
      cout << ans[i];
    }
    cout << endl;
  }
  return 0;
}
