#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  bool ok = true;
  cin >> n >> m;
  vector<pair<int, int>> p(m);
  vector<int> ans(n);
  for (int i = 0; i < (n); ++i) {
    ans[i] = -1;
  }
  for (int i = 0; i < (m); ++i) {
    cin >> p[i].first >> p[i].second;
    if (ans[p[i].first] != -1 && ans[p[i].first] != p[i].second) {
      ok = false;
    }
    ans[p[i].first - 1] = p[i].second;
  }
  for (int i = 0; i < (n); ++i) {
    if (ans[i] == -1) {
      if (i == 0 && n > 1) {
        ans[i] = 1;
      } else {
        ans[i] = 0;
      }
    }
  }
  int a = 0;
  for (int i = 0; i < (n); ++i) {
    a += ans[i] * pow(10, n - i - 1);
  }
  if (ok == false) {
    cout << -1 << endl;
    return 0;
  }
  cout << a << endl;
  return 0;
}
