#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M, s, c;
  cin >> N >> M;
  bool check[N];
  int dig[N];
  for (int i = 0; i < N; i++) {
    check[i] = false;
    dig[i] = 0;
  }
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    s -= 1;
    if (check[s] and c != dig[s]) {
      cout << -1 << endl;
      return 1;
    }
    if (N != 1 and s == 0 and c == 0) {
      cout << -1 << endl;
      return 1;
    }
    check[s] = true;
    dig[s] = c;
  }
  int retval = 0;
  if (dig[0] == 0) dig[0] = 1;
  for (int i = 0; i < N; i++) {
    retval += pow(10, N - i - 1) * dig[i];
  }
  cout << retval << endl;
  return 0;
}
