#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, t, l, i, a, b;
  cin >> n >> t;
  map<long long, long long> m;
  while (t--) {
    cin >> a >> b;
    if (m[a] > 0 && m[a] != b) {
      cout << -1;
      return 0;
    }
    m[a] = b;
  }
  if (n > 1 && m[1] == 0) {
    cout << -1;
    return 0;
  }
  for (i = 1; i <= n; i++) {
    cout << m[i];
  }
  return 0;
}
