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