#include <bits/stdc++.h>
int main() {
  std::vector<std::pair<int, int>> v;
  int n, m;
  std::cin >> n >> m;
  int s, c;
  while (m--) {
    std::cin >> s >> c;
    v.push_back(std::make_pair(s, c));
  }
  int arr[] = {-1, -1, -1};
  bool flag = true;
  for (auto i : v) {
    if (i.first == 1 && i.second == 0 && n > 1) {
      flag = false;
      break;
    }
    if (arr[i.first - 1] == -1)
      arr[i.first - 1] = i.second;
    else if (arr[i.first - 1] != -1 && arr[i.first - 1] != i.second) {
      flag = false;
      break;
    }
  }
  if (flag) {
    for (int i = 0; i < n; ++i) {
      if (arr[i] == -1)
        std::cout << 0;
      else
        std::cout << arr[i];
    }
    std::cout << std::endl;
  } else
    std::cout << "-1" << std::endl;
}
