#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, x;
  cin >> N;
  cin >> M;
  vector<int> s(M), c(M), f(N, -1);
  for (int i = 0; i < M; i++) {
    cin >> s.at(i);
    cin >> c.at(i);
  }
  for (int i = 0; i < M; i++) {
    if (f.at(s.at(i) - 1) == -1) {
      f.at(s.at(i) - 1) = c.at(i);
    } else {
      if (f.at(s.at(i) - 1) != c.at(i)) {
        cout << -1;
        return 0;
      }
      f.at(s.at(i) - 1) = c.at(i);
    }
  }
  x = 0;
  for (int i = 0; i < N; i++) {
    if (f.at(i) != -1) {
      x = x + f.at(N - 1 - i) * pow(10, i);
    }
  }
  cout << x;
  return 0;
}
