#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int ma[4];
  for (int i = 0; i < (int)(3); i++) {
    ma[i + 1] = (int)2e9;
  }
  for (int i = 0; i < (int)(m); i++) {
    int s, c;
    cin >> s >> c;
    if (ma[s] == (int)2e9) {
      ma[s] = c;
    } else if (ma[s] == c) {
      continue;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (ma[1] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < (int)(3); i++) {
    if (ma[i + 1] != (int)2e9) {
      cout << ma[i + 1];
    } else {
      if (i == 0)
        cout << 1;
      else
        cout << 0;
    }
  }
  cout << endl;
  return 0;
}
