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