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