#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  int ppp, pp;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  if (N == 1) {
    int c1 = c.at(0);
    for (int i = 0; i < M; i++) {
      c.at(i) -= c1;
      if (c.at(i) != 0) {
        cout << -1 << endl;
        return 0;
      }
    }
    cout << c1 << endl;
  } else {
    int res = pow(10, N - 1);
    int S, C;
    for (int i = 0; i < M; i++) {
      for (int j = 0; j < M; j++) {
        if (s.at(i) == s.at(j)) {
          if (c.at(i) != c.at(j)) {
            cout << -1 << endl;
            return 0;
          }
        }
      }
    }
    for (int i = 0; i < M; i++) {
      S = s.at(i);
      C = c.at(i);
      if (S == 1 && C == 0) {
        cout << -1 << endl;
        return 0;
      }
      ppp = pow(10, N - S + 1);
      pp = pow(10, N - S);
      res = res - res % ppp / pp * pp + C * pow(10, N - S);
    }
    cout << res << endl;
  }
}
