#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < (int)(m); i++) {
    cin >> s.at(i) >> c.at(i);
  }
  bool is = true;
  for (int i = 0; i < (int)(m); i++) {
    for (int j = 0; j < (int)(m); j++) {
      if (i == j) {
        continue;
      }
      if (s.at(i) == s.at(j) && c.at(i) != c.at(j)) {
        is = false;
      }
    }
  }
  if (!is) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i < (int)(m); i++) {
    if (n == 1 && s.at(i) == 1 && c.at(i) == 0) {
      cout << 0;
      return 0;
    }
    if (n != 1 && s.at(i) == 1 && c.at(i) == 0) {
      cout << -1;
      return 0;
    }
  }
  vector<int> ans(n);
  for (int i = 0; i < (int)(m); i++) {
    ans.at(s.at(i) - 1) = c.at(i);
  }
  if (ans.at(0) == 0) {
    ans.at(0) = 1;
  }
  for (int i = 0; i < (int)(n); i++) {
    cout << ans.at(i);
  }
}
