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