#include <bits/stdc++.h>
int main(int argc, char* pArgv[]) {
  int n = 0, m = 0;
  std::cin >> n >> m;
  std::vector<int> a(n, -1);
  bool doesExist = true;
  for (auto index = 0; index < m; index++) {
    int s = 0, c = 0;
    std::cin >> s >> c;
    if (a[s - 1] < 0) {
      a[s - 1] = c;
    } else if (a[s - 1] != c) {
      doesExist = false;
      break;
    }
  }
  for (auto index = 0; index < n; index++) {
    std::cerr << a[index] << " ";
  }
  std::cerr << std::endl;
  if (doesExist) {
    if (1 < n && a[0] <= 0) {
      doesExist = false;
    }
  }
  if (!doesExist) {
    std::cout << -1 << std::endl;
  } else {
    int64_t v = 0;
    for (int index = n - 1; 0 <= index; index--) {
      int w = (a[index] == -1) ? 0 : a[index];
      v = v * 10 + w;
    }
    std::cout << v << std::endl;
  }
  return 0;
}
