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