#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  vector<int> digit(N, -1);
  int s;
  int alt;
  int ans = 0;
  int end = 0;
  for (int i = 0; i < M; i++) {
    cin >> s;
    alt = digit[s - 1];
    cin >> digit[s - 1];
    if (alt != -1 && alt != digit[s - 1]) {
      end = 1;
      break;
    } else if (digit[N - 1] == 0 && N != 1) {
      end = 1;
      break;
    } else if (digit[N - 1] == 0 && N == 1) {
      end = 2;
      break;
    }
  }
  if (end == 1) {
    cout << -1 << endl;
  } else if (end == 2) {
    cout << 0 << endl;
  } else {
    for (int i = 0; i < N; i++) {
      if (digit[i] == -1) {
        if (i == N - 1) {
          digit[i] = 1;
        } else {
          digit[i] = 0;
        }
      }
    }
    for (int i = 0; i < N; i++) {
      ans += digit[N - 1 - i] * pow(10, i);
    }
    cout << ans << endl;
  }
}
