#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int cs, cc;
  int ds[3] = {-1, -1, -1};
  for (int i = 0; i < m; i++) {
    cin >> cs >> cc;
    cs--;
    if (ds[cs] < 0)
      ds[cs] = cc;
    else if (ds[cs] != cc)
      ds[cs] = 11;
  }
  if (n > 1 && ds[0] == 0)
    cout << "-1" << endl;
  else if (ds[0] > 9 || ds[1] > 9 || ds[2] > 9)
    cout << "-1" << endl;
  else {
    ds[0] = max(ds[0], 1);
    ds[1] = max(ds[1], 0);
    ds[2] = max(ds[2], 0);
    if (n == 2)
      swap(ds[0], ds[1]);
    else if (n == 3)
      swap(ds[0], ds[2]);
    cout << (ds[0] + ds[1] * 10 + ds[2] * 100) << endl;
  }
  return 0;
}
