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