#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  bool res = true;
  vector<int> tmp(n, 11);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    if (a == 1 && b == 0) {
      res = false;
    } else if (tmp[a - 1] == 11) {
      tmp[a - 1] = b;
    } else if (tmp[a - 1] != b) {
      res = false;
    }
  }
  if (res) {
    for (int i = 0; i < n; ++i) {
      if (tmp[i] == 11)
        cout << 0;
      else
        cout << tmp[i];
    }
  } else {
    cout << -1;
  }
  cout << endl;
}
