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