#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, s[10], c[10], keta = 1, ans = 0;
  bool ok = true;
  map<int, int> mp;
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  for (int i = 0; i < m; i++) {
    if (s[i] == 1 && c[i] == 0 && n != 1) {
      ok = false;
      break;
    }
    if (mp.find(s[i]) == mp.end()) {
      mp[s[i]] = c[i];
    } else {
      if (mp[s[i]] != c[i]) {
        ok = false;
        break;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    keta *= 10;
  }
  keta /= 10;
  if (ok) {
    for (int i = 1; i <= n; i++) {
      if (mp.find(i) != mp.end()) {
        ans += mp[i] * keta;
      }
      keta /= 10;
    }
    if (ans != 0)
      cout << ans << endl;
    else
      cout << 1 << endl;
  } else {
    cout << "-1" << endl;
  }
}
