#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  vector<int> a, b;
  int ans = 0;
  cin >> n >> m;
  vector<int> nv(n, -1);
  bool ansF = true;
  for (int i = 0; i < m; i++) {
    int k, v;
    cin >> k >> v;
    k = k - 1;
    if (nv[k] == v || nv[k] == -1) {
      nv[k] = v;
    } else {
      ans = -999;
    }
  }
  if (ans != -999) {
    for (int i = 0; i < n; i++) {
      if (i == 0 && nv[i] == 0) {
        cout << -1 << endl;
        ansF = false;
      }
      if (nv[i] == -1) {
        if (i == 0) {
          nv[i] = 1;
        } else {
          nv[i] = 0;
        }
      }
      ans = (ans + nv[i]) * 10;
    }
    ans = ans / 10;
    if (ans) {
      cout << ans << endl;
    }
  } else {
    cout << -1 << endl;
  }
}
