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