#include <bits/stdc++.h>
int main() {
  int N, M;
  scanf("%d", &N);
  scanf("%d", &M);
  std::vector<int> s(M), c(M);
  std::map<int, int> mp;
  for (int i = 0; i < M; i++) {
    scanf("%d", &s[i]);
    scanf("%d", &c[i]);
    for (auto entry : mp) {
      if (entry.first == s[i] && entry.second != c[i]) {
        printf("-1\n");
        return 0;
      }
    }
    mp[s[i]] = c[i];
  }
  int mp_max = 0;
  int N_value;
  bool Nset = false;
  for (auto entry : mp) {
    mp_max = std::max(mp_max, entry.first);
    if (entry.first == 1) {
      Nset = true;
      N_value = entry.second;
    }
  }
  if (mp_max > N) {
    printf("-1\n");
  } else if (Nset && N_value == 0 && N != 1) {
    printf("-1\n");
  } else {
    int ans = 0;
    for (int i = 1; i <= N; i++) {
      for (auto entry : mp) {
        if (entry.first == i) {
          ans += (int)pow(10, N - i) * entry.second;
        }
        if (i == 1 && ans == 0 && N != 1) {
          ans += (int)pow(10, N - 1);
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
