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