#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  int result = 0;
  result += pow(10, N - 1);
  bool tmp = false;
  for (int i = 0; i < M; i++) {
    tmp = false;
    for (int j = 0; j < i; j++) {
      if (s.at(i) == s.at(j)) {
        tmp = true;
        break;
      }
    }
    if (tmp) {
      continue;
    }
    if (s.at(i) == 1) {
      result += (c.at(i) - 1) * (int)pow(10, N - s.at(i));
    } else {
      result += c.at(i) * (int)pow(10, N - s.at(i));
    }
  }
  for (int i = 0; i < M; i++) {
    for (int j = i + 1; j < M; j++) {
      if (s.at(i) == s.at(j) && c.at(i) != c.at(j)) {
        result = -1;
      }
    }
  }
  for (int i = 0; i < M; i++) {
    if (N != 1 && s.at(i) == 1 && c.at(i) == 0) {
      result = -1;
    }
  }
  cout << result << endl;
}
