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