#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ns(n);
  for (int i = 0; i < (n); ++i) ns.at(i) = -1;
  int f = 0;
  int hu = 0;
  for (int i = 0; i < (m); ++i) {
    int k, su;
    cin >> k >> su;
    if (k != n) hu++;
    if (ns.at(k - 1) == -1) {
      ns.at(k - 1) = su;
    } else {
      if (ns.at(k - 1) != su) f = 1;
    }
  }
  for (int i = 0; i < n - 1; i++) {
    if (ns.at(i) == -1) {
    } else if (ns.at(i) != 0) {
      break;
    } else {
      f = 1;
      break;
    }
  }
  if (f == 1) {
    cout << -1 << endl;
  } else {
    int a = 0;
    for (int i = 0; i < (n); ++i) {
      if (ns.at(i) != -1) {
        a += ns.at(i) * pow(10, n - i - 1);
      }
    }
    cout << a << endl;
  }
}
