#include <bits/stdc++.h>
using namespace std;
int n, m, a = 0;
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int s, c, t = 1, b;
    cin >> s >> c;
    for (int j = 0; j < n - s; j++) t *= 10;
    b = a % (10 * t) / t;
    if ((b != 0 && b != c) || (n > 1 && s == 1 && c == 0)) {
      a = -1;
      break;
    } else if (b == 0)
      a += c * t;
  }
  cout << a << endl;
  return 0;
}
