#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<int> ans(n, -1);
  bool flag = true;
  for (ll i = 0; i < (m); ++i) {
    int s, c;
    std::cin >> s >> c;
    s--;
    if (ans[s] == -1 || ans[s] == c)
      ans[s] = c;
    else
      flag = false;
  }
  if (ans[0] == 0) flag = false;
  if (flag) {
    if (n != 1)
      for (ll i = 0; i < (n); ++i) {
        if (ans[i] != -1)
          std::cout << ans[i];
        else if (i == 0 && ans[i] == -1)
          std::cout << "1";
        else if (ans[i] == -1)
          std::cout << "0";
      }
    else {
      if (ans[0] != -1)
        std::cout << ans[0];
      else
        std::cout << "0";
    }
  } else
    std::cout << "-1";
  std::cout << '\n';
  return 0;
}
