#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> p(m);
  for (int i = 0; i < (int)m; i++) {
    int s, c;
    cin >> s >> c;
    p.at(i) = make_pair(s, c);
  }
  for (int i = 0; i < (int)m - 1; i++) {
    for (int j = i; j < m; ++j) {
      if (p[i].first == p[j].first && p[i].second != p[j].second) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  vector<int> count(3);
  for (int i = 0; i < (int)m; i++) {
    count[p[i].first - 1]++;
  }
  for (int i = 0; i < (int)m; i++) {
    if (p[i].first == 1) {
      if (p[i].second == 0) {
        cout << -1 << endl;
        return 0;
      } else {
        cout << p[i].second;
        break;
      }
    }
  }
  if (count[0] == 0) cout << 1;
  for (int i = 0; i < (int)m; i++) {
    if (m >= 2 && p[i].first == 2) {
      cout << p[i].second;
      break;
    }
  }
  if (count[1] == 0) cout << 0;
  for (int i = 0; i < (int)m; i++) {
    if (m == 3 && p[i].first == 3) {
      cout << p[i].second;
      break;
    }
  }
  if (count[2] == 0) cout << 0;
}
