#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  map<int, int> b;
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < m; i++) {
    b[s[i]] = 10;
  }
  int mi;
  for (int i = 0; i < m; i++) {
    mi = b[s[i]];
    if (b[s[i]] == c[i]) {
      b[s[i] + 100] = c[i];
    }
    b[s[i]] = min(mi, c[i]);
  }
  for (int i = 0; i < m; i++) {
    if (n >= 2 && s[i] == 1 && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (b.size() != m) {
    cout << -1 << endl;
    return 0;
  }
  vector<int> ans(n);
  for (int k = 1; k <= n; k++) {
    for (int i = 0; i < m; i++) {
      if (s[i] == k) {
        ans[k - 1] = c[i];
      }
    }
  }
  if (ans[0] == 0) {
    ans[0] = 1;
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i];
  }
  cout << endl;
  return 0;
}
