#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<bool> check(n);
  int anser = 0;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (n > 1 && s == 1 && c == 0) {
      cout << "-1" << endl;
      return 0;
    }
    if (n < s) {
      cout << "-1" << endl;
      return 0;
    }
    int t = n - s;
    if (check[t] == true) {
      bool test = false;
      if (t == 2) test = anser / 100 == c;
      if (t == 1) test = (anser % 100) / 10 == c;
      if (t == 0) test = (anser % 10) == c;
      if (test == false) {
        cout << "-1" << endl;
        return 0;
      }
    } else {
      if (t == 2) anser += c * 100;
      if (t == 1) anser += c * 10;
      if (t == 0) anser += c;
      check[t] = true;
    }
  }
  cout << anser << endl;
  return 0;
}
