#include <bits/stdc++.h>
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int n, m;
  std::cin >> n >> m;
  std::vector<int> p(n, 0);
  bool pb[4] = {false};
  int ans = 0;
  bool flag = true;
  for (int i = 0; i < m; i++) {
    int s, c;
    std::cin >> s >> c;
    if (pb[s - 1] && p[s - 1] != c) {
      flag = false;
    } else {
      p[s - 1] = c;
      pb[s - 1] = true;
    }
  }
  for (int i = 0; i < n; i++) {
    ans += p[i];
  }
  if ((ans == 0 && n != 1) || (n != 1 && p[0] == 0)) {
    flag = false;
  }
  if (!flag) {
    std::cout << -1 << std::endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    std::cout << p[i];
  }
  std::cout << std::endl;
END:
  return 0;
}
