#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long n, m;
  cin >> n >> m;
  long long b[3];
  for (long long i = 0; i < 3; ++i) b[i] = -1;
  for (long long i = 0; i < m; ++i) {
    long long x, y;
    cin >> x >> y;
    --x;
    if (b[x] == -1) {
      b[x] = y;
      if (x == 0 && y == 0) {
        cout << -1 << endl;
        return 0;
      }
    } else {
      if (b[x] != y) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (long long i = 0; i < 3; ++i) {
    if (b[i] == -1) {
      if (i == 0)
        cout << 1;
      else
        cout << 0;
    } else {
      cout << b[i];
    }
  }
  cout << endl;
}
