#include <bits/stdc++.h>
using namespace std;
int digit(int i, int c, int N) {
  int M = floor(i / pow(10, N - c));
  int ret = M % 10;
  return ret;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> C(M, vector<int>(2));
  for (int i = (int)(0); i < (int)(M); i++) {
    cin >> C[i][0] >> C[i][1];
  }
  for (int i = (int)(0); i < (int)(pow(10, N)); i++) {
    for (int j = (int)(0); j < (int)(M); j++) {
      if (digit(i, C[j][0], N) != C[j][1] || digit(i, 1, N) == 0) {
        break;
      } else {
        if (j == M - 1) {
          cout << i << endl;
          return 0;
        }
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
