#include <bits/stdc++.h>
using namespace std;
template <typename T>
void fin(T a) {
  cout << a << endl;
  exit(0);
}
signed main() {
  int n, m;
  cin >> n >> m;
  vector<int> v(n, -1);
  while (m--) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && c == 0) fin(-1);
    if (~v[s - 1] && v[s - 1] != c) fin(-1);
    v[s - 1] = c;
  }
  if (!~v[0]) v[0] = 1;
  for (int i = 0; i < n; i++) {
    cout << (~v[i] ? v[i] : 0);
  }
  cout << endl;
}
