#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int s[M], c[M];
  for (int i = 0; i < M; ++i) {
    cin >> s[i] >> c[i];
  }
  int ans = 0;
  map<int, int> deta;
  deta[0] = -1;
  deta[1] = -1;
  deta[2] = -1;
  deta[3] = -1;
  deta[4] = -1;
  for (int i = 0; i < M; ++i) {
    if (s[i] == 1 & c[i] == 0 & N > 1) {
      ans = -1;
      break;
    }
    if (deta[s[i]] != c[i] & deta[s[i]] != -1) {
      ans = -1;
      break;
    }
    if (deta[s[i]] == c[i]) continue;
    deta[s[i]] = c[i];
    ans += c[i] * pow(10, N - s[i]);
  }
  if (ans != -1 & int(ans / pow(10, N - 1)) == 0) ans += pow(10, N - 1);
  if (M == 0 & N == 1) ans = 0;
  cout << ans << endl;
}
