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