#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  bool ansis = true;
  vector<int> keta(n);
  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    if (keta.at(s - 1) && keta.at(s - 1) != c)
      ansis = false;
    else
      keta.at(s - 1) = c;
  }
  if (n > 1 && keta.at(0) == 0) ansis = false;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += pow(10, i) * keta.at(n - 1 - i);
  }
  if (ansis)
    cout << ans << endl;
  else
    cout << -1 << endl;
}
