#include <bits/stdc++.h>
using namespace std;
int main() {
  map<int, int> hash;
  int N, M;
  cin >> N >> M;
  while (M--) {
    int s, c;
    cin >> s >> c;
    if (hash.find(s) != hash.end() && hash[s] != c) {
      cout << -1;
      return 0;
    }
    hash[s] = c;
  }
  int res = 1;
  if (hash.find(1) != hash.end()) {
    if (hash[1] == 0) {
      cout << -1;
      return 0;
    }
    res = hash[1];
  }
  N--;
  int pos = 2;
  while (N--) {
    res = res * 10;
    if (hash[pos]) res += hash[pos];
    pos++;
  }
  cout << res;
  return 0;
}
