#include <bits/stdc++.h>
typedef struct {
  int s;
  int c;
} Rest;
int main() {
  int n, m;
  std::cin >> n;
  std::cin >> m;
  std::vector<Rest> rest(m);
  for (int i = 0; i < m; ++i) {
    std::cin >> rest[i].s;
    std::cin >> rest[i].c;
  }
  std::vector<int> ans_rest(n + 1, -1);
  int ans = 0;
  for (int i = 0; i < m; ++i) {
    if (rest[i].s == 1 && rest[i].c == 0 && n != 1) ans = -1;
    if (ans_rest[rest[i].s] == -1)
      ans_rest[rest[i].s] = rest[i].c;
    else if (ans_rest[rest[i].s] != rest[i].c)
      ans = -1;
  }
  if (ans != -1) {
    for (int i = 1; i <= n; ++i)
      if (ans_rest[i] != -1) ans += ans_rest[i] * pow(10, n - i);
    if (ans_rest[1] == -1) ans += pow(10, n - 1);
  }
  std::cout << ans;
}
