#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;
  bool bb = 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 = i + 1; j < M; j++) {
      if (s.at(i) == s.at(j)) {
        if (c.at(i) != c.at(j)) {
          b = true;
        }
      }
    }
  }
  for (int i = 0; i < M; i++) {
    if (s.at(i) == 1) {
      bb = true;
      break;
    }
  }
  for (int i = 0; i < M; i++) {
    for (int j = i + 1; j < M; 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 {
    if (bb == true) {
      cout << sum << endl;
    } else {
      cout << sum + pow(10, N - 1) << endl;
    }
  }
}
