#include <bits/stdc++.h>
using namespace std;
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
int main() {
  int N, M;
  cin >> N >> M;
  map<int, int> A;
  vector<int> s(M), c(M);
  for (long long i = 0; i < (long long)(M); i++) {
    cin >> s.at(i) >> c.at(i);
    if (A[s.at(i)] != c.at(i) && A[s.at(i)] != 0) {
      cout << -1 << endl;
      return 0;
    }
    A[s.at(i)] = c.at(i);
  }
  if (A[1] == 0) {
    cout << -1 << endl;
  } else {
    for (int i = 1; i <= N; i++) {
      cout << A[i];
    }
  }
  cout << endl;
}
