#include <bits/stdc++.h>
using namespace std;
int n, x, y, m;
int a[15];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  set<int> s1;
  set<int> s2;
  set<int> s3;
  bool flag = false;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    if (x == 1) s1.insert(y);
    if (x == 2) s2.insert(y);
    if (x == 3) s3.insert(y);
  }
  if ((s1.size() > 0 && *(s1.begin()) == 0) || s1.size() > 1 || s2.size() > 1 ||
      s3.size() > 1) {
    cout << "-1" << endl;
    return 0;
  }
  if (n > 0)
    if (s1.size() > 0)
      cout << *(s1.begin());
    else
      cout << "1";
  if (n > 1) {
    if (s2.size() > 0)
      cout << *(s2.begin());
    else
      cout << "0";
  }
  if (n == 3) {
    if (s3.size() > 0)
      cout << *(s3.begin());
    else
      cout << "0";
  }
  cout << endl;
  return 0;
}
