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