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