#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
int main() {
  int N, M;
  cin >> N >> M;
  vi val(N, -1);
  bool invalid = false;
  for (int i = 0; i < (int)(M); ++i) {
    int s, c;
    cin >> s >> c;
    if (val[s - 1] == -1) {
      val[s - 1] = c;
    } else if (val[s - 1] != c) {
      invalid = true;
      break;
    }
  }
  if (val[0] == 0 && N > 1) {
    invalid = true;
  }
  if (invalid) {
    cout << -1 << endl;
    return 0;
  }
  int power = 1;
  int num = 0;
  while (!val.empty()) {
    int v = val.back();
    val.pop_back();
    if (v == -1) {
      if (!val.empty()) {
        v = 0;
      } else {
        v = 1;
      }
    }
    num += v * power;
    power *= 10;
  }
  cout << num << endl;
  return 0;
}
