#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  int sum = 0;
  bool b = false;
  for (int i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  for (int i = 0; i < M; i++) {
    if (s.at(i) == 1 && c.at(i) == 0) {
      if (N != 1) {
        b = true;
      }
    }
  }
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < M; j++) {
      if (i != j) {
        if (s.at(i) == s.at(j)) {
          if (c.at(i) != c.at(j)) {
            b = true;
          }
        }
      }
    }
  }
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < M; j++) {
      if (i != j) {
        if (s.at(i) == s.at(j)) {
          if (c.at(i) == c.at(j)) {
            c.at(j) = 0;
          }
        }
      }
    }
  }
  for (int i = 0; i < M; i++) {
    sum = sum + c.at(i) * pow(10, N - s.at(i));
  }
  if (b == true) {
    cout << "-1" << endl;
  } else {
    cout << sum << endl;
  }
}
