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