#include <bits/stdc++.h>
using namespace std;
int a[4];
bitset<4> mark;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m, s, c;
  cin >> n >> m;
  if (n == 1) {
    for (int i = 0; i < m; ++i) {
      cin >> s >> c;
      s--;
      if (mark[0] && c != a[0]) {
        cout << "-1\n";
        return 0;
      }
      if (c == 0) {
        cout << -1 << '\n';
        return 0;
      }
      mark[0] = true;
      a[0] = c;
    }
    if (!mark[0])
      cout << 0 << '\n';
    else
      cout << a[0] << '\n';
  } else if (n == 2) {
    for (int i = 0; i < m; ++i) {
      cin >> s >> c;
      s--;
      if (mark[s] && c != a[s]) {
        cout << "-1\n";
        return 0;
      }
      if (s == 0 && c == 0) {
        cout << -1 << '\n';
        return 0;
      }
      mark[s] = true;
      a[s] = c;
    }
    if (!mark[1]) a[1] = 0;
    if (!mark[0]) a[0] = (!a[1]) ? 1 : 0;
    cout << a[0] << a[1] << '\n';
  } else {
    for (int i = 0; i < m; ++i) {
      cin >> s >> c;
      s--;
      if (mark[s] && c != a[s]) {
        cout << "-1\n";
        return 0;
      }
      if (s == 0 && c == 0) {
        cout << -1 << '\n';
        return 0;
      }
      mark[s] = true;
      a[s] = c;
    }
    if (!mark[2]) a[2] = 0;
    if (!mark[1]) a[1] = (!a[2]) ? 1 : 0;
    if (!mark[0]) a[0] = (!a[2] && !a[1]) ? 1 : 0;
    cout << a[0] << a[1] << a[2] << '\n';
  }
  return 0;
}
