#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  bool result = true;
  for (int i = 0; i < (m); ++i) {
    cin >> s[i] >> c[i];
  }
  vector<int> val(4);
  for (int i = 0; i < (4); ++i) {
    val[i] = -1;
  }
  for (int i = 0; i < (m); ++i) {
    if ((s[i] == 2 || s[i] == 3) && n == 1) {
      result = false;
    } else if (s[i] == 3 && n == 2) {
      result = false;
    } else if (n != 1 && c[i] == 0 && s[i] == 1) {
      result = false;
    } else if (val[s[i]] == -1 || val[s[i]] == c[i]) {
      val[s[i]] = c[i];
    } else {
      result = false;
    }
  }
  int ans = 0;
  int ten = 1;
  int count_n = n;
  if (result == false) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = (1); i < (n + 1); ++i) {
    for (int i = 0; i < (count_n - 1); ++i) ten *= 10;
    if (val[i] == -1 && i == 1) {
      ans += ten;
    } else if (val[i] == -1 && i != 1) {
      ans += 0;
    } else {
      ans += val[i] * ten;
    }
    ten = 1;
    count_n--;
  }
  cout << ans << endl;
}
