#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  int ans = -1;
  vector<int> v(N, -1);
  bool b = true;
  for (int i = 0; i < M; i++) {
    if (v[s[i]] == -1 || v[s[i]] == c[i]) {
      v[s[i]] = c[i];
    } else {
      b = false;
      break;
    }
  }
  if (N > 0 && v[0] == 0) b = false;
  if (b) {
    string tmp = "";
    for (int i = 0; i < N; i++) {
      if (v[i] == -1) {
        if (i == 0) {
          v[i] = 1;
        } else {
          v[i] = 0;
        }
      }
      tmp += to_string(v[i]);
    }
    ans = stoi(tmp);
  }
  cout << ans << endl;
}
