#include <bits/stdc++.h>
using namespace std;
int getNumber(vector<int> x) {
  int ans = 0;
  for (int i = 0; i < x.size(); i++) {
    int k = 1;
    for (int j = 0; j < (x.size() - i - 1); j++) {
      k *= 10;
    }
    ans += x.at(i) * k;
  }
  return ans;
}
int main() {
  int ans = 0;
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  if (N >= 2) {
    for (int i = 0; i < M; i++) {
      if (s.at(i) == 1 && c.at(i) == 0) {
        ans = -1;
      }
    }
  }
  for (int i = 0; i < M - 1; i++) {
    for (int j = i + 1; j < M; j++) {
      if (s.at(i) == s.at(j) && c.at(i) != c.at(j)) {
        ans = -1;
      }
    }
  }
  if (ans == -1) {
    cout << ans << endl;
    return 0;
  }
  vector<int> a(N);
  for (int i = 0; i < M; i++) {
    a.at(s.at(i) - 1) = c.at(i);
  }
  if (a.at(0) == 0) a.at(0) = 1;
  cout << getNumber(a) << endl;
}
