#include <bits/stdc++.h>
int main(void) {
  int n, m;
  std::cin >> n >> m;
  bool flag = false;
  std::vector<int> a(n, -1);
  int s, c;
  for (int i = 0; i < m; i++) {
    std::cin >> s >> c;
    if (a[s - 1] == -1 || a[s - 1] == c) {
      a[s - 1] = c;
    } else {
      std::cout << -1 << std::endl;
      flag = !flag;
      break;
    }
  }
  std::string ans = "";
  if (!flag) {
    if (a[0] > 0) {
    } else if (a[0] == -1 && n != 1) {
      ans.push_back(1);
    } else if (a[0] < 0 && n == 1) {
      std::cout << 0 << std::endl;
      flag = !flag;
    } else {
      std::cout << -1 << std::endl;
      flag = !flag;
    }
  }
  if (!flag) {
    for (int i = 1; i < n; i++) {
      if (a[i] > 0) {
      } else {
        a[i] = 0;
      }
    }
    for (auto i : a) {
      std::cout << i << "";
    }
    std::cout << std::endl;
  }
}
