#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, miss = 0, mn = 10;
  cin >> n >> m;
  map<int, int> s;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    mn = min(mn, a);
    if (a == 1 && b == 0 && n != 1) {
      miss++;
      break;
    } else if (s.count(a)) {
      if (s[a] == b)
        continue;
      else {
        miss++;
        break;
      }
    } else
      s[a] = b;
  }
  if (miss != 0)
    cout << -1 << endl;
  else {
    int ans = 0;
    if (mn != 1 && m != 0) ans += pow(10, n - 1);
    for (auto p : s) {
      auto k = p.first;
      auto t = p.second;
      ans += pow(10, n - k) * t;
    }
    cout << ans << endl;
  }
}
