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