#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int a[N], flg[N];
  for (int i = 0; i < N; i++) {
    a[i] = 0;
    flg[i] = 0;
  }
  int b, c;
  for (int i = 0; i < M; i++) {
    cin >> b >> c;
    if (flg[b - 1] == 1 && a[b - 1] != c) {
      cout << -1 << endl;
      return 0;
    }
    a[b - 1] = c;
    flg[b - 1] = 1;
  }
  if (a[0] == 0 && flg[0] == 0) {
    a[0] = 1;
  }
  int result = 0;
  for (int i = (N - 1); i >= 0; i--) {
    result += (a[i] * pow(10, (N - i - 1)));
  }
  if (result == 0 && N == 1 && flg[0] == 1) {
    cout << 0 << endl;
    return 0;
  }
  int zeroflg = 0;
  for (int i = 0; i < N; i++) {
    if (a[N - i - 1] == 0) {
      zeroflg = 1;
    } else {
      zeroflg = 0;
    }
  }
  if (zeroflg == 1) {
    cout << -1 << endl;
    return 0;
  }
  cout << result << endl;
  return 0;
}
