#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M), num(N, -1);
  int ans;
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < M; i++) {
    if (N != 1 and s[i] == 1 and c[i] == 0) {
      ans = -1;
      cout << ans << endl;
      return 0;
    } else {
      if (num[N - s[i]] == -1 or num[N - s[i]] == c[i]) {
        num[N - s[i]] = c[i];
      } else {
        ans = -1;
        cout << ans << endl;
        return 0;
      }
    }
  }
  if (num[N - 1] == -1) {
    num[N - 1] = 1;
  }
  for (int i = 0; i < N - 1; i++) {
    if (num[i] == -1) {
      num[i] = 0;
    }
  }
  ans = 0;
  for (int i = 0; i < N; i++) {
    ans += int(num[i] * pow(10, i));
  }
  cout << ans << endl;
}
