#include <bits/stdc++.h>
using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;
int main(void) {
  Int n, m;
  cin >> n >> m;
  vector<Int> v(n, -1);
  bool result = true;
  for (Int i = 0; i < m; ++i) {
    Int s, c;
    cin >> s >> c;
    --s;
    if (v[s] == -1) {
      v[s] = c;
    } else if (v[s] == c) {
    } else {
      result = false;
    }
  }
  if (v[0] == 0) {
    result = false;
  } else if (v[0] == -1 && n == 1) {
    v[0] = 0;
  } else if (v[0] == -1 && n != 1) {
    v[0] = 1;
  }
  for (Int i = 1; i < n; ++i) {
    if (v[i] == -1) {
      v[i] = 0;
    }
  }
  Int answer = 0;
  if (!result) {
    answer = -1;
  } else {
    for (Int i = 0; i < n; ++i) {
      answer *= 10;
      answer += v[i];
    }
  }
  cout << answer << endl;
  return 0;
}
