#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  int out[3];
  vector<int> s, c;
  for (int i = 0; i < 3; ++i) out[i] = -1;
  int keta, num;
  for (int i = 0; i < m; ++i) {
    cin >> keta >> num;
    s.push_back(keta);
    c.push_back(num);
  }
  for (int i = 0; i < m; ++i) {
    keta = s[i];
    num = c[i];
    if (keta == 1 && num == 0) {
      cout << -1 << endl;
      return 0;
    } else if (out[2 - n + keta] == -1) {
      out[2 - n + keta] = num;
    } else if (num != out[2 - n + keta]) {
      cout << -1 << endl;
      return 0;
    } else {
      out[2 - n + keta] = num;
    }
  }
  for (int i = 3 - n; i < 3; ++i) {
    num = out[i];
    if (num == -1) {
      if (i == 3 - n) {
        cout << 1;
      } else {
        cout << 0;
      }
    } else {
      cout << num;
    }
  }
  cout << endl;
  return 0;
}
