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