#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  bool a = true;
  cin >> n >> m;
  vector<int> v(4, -1);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (v[s] == -1 || v[s] == c)
      v[s] = c;
    else {
      a = false;
      break;
    }
  }
  if (v[1] == 0)
    a = false;
  else if (v[1] == -1)
    v[1] = 1;
  if (v[2] == -1) v[2] = 0;
  if (v[3] == -1) v[3] = 0;
  if (a) {
    for (int i = 1; i < n + 1; i++) {
      cout << v[i];
    }
  } else if (n == 1 && v[1] == 0) {
    cout << 0;
  } else {
    cout << -1 << endl;
  }
}
