#include <bits/stdc++.h>
struct max_min {
  int64_t max = 0;
  int64_t min = 0;
};
const int64_t cc = pow(10, 9) + 7;
bool sort_pair(std::pair<int64_t, int64_t> origin,
               std::pair<int64_t, int64_t> another) {
  return origin.first < another.first;
}
int main() {
  std::string word = "aa";
  int64_t a, b, c, d, e, f;
  std::vector<std::pair<int64_t, int64_t> > list;
  std::cin >> a;
  std::cin >> b;
  for (int i = 0; i < b; i++) {
    std::pair<int64_t, int64_t> dd;
    std::cin >> dd.first;
    std::cin >> dd.second;
    list.push_back(dd);
  }
  std::sort(list.begin(), list.end(), sort_pair);
  for (int i = 0; i < list.size(); i++) {
    if (list[i].first == 1 && list[i].second == 0 && a != 1) {
      c = -1;
      break;
    }
    if (list[i].first > a) {
      c = -1;
      break;
    }
    if (i == 0) {
      c = pow(10, a - list[i].first) * list[i].second;
    } else {
      if (list[i].first == list[i - 1].first) {
        if (list[i].second == list[i - 1].second) {
          continue;
        } else {
          c = -1;
          break;
        }
      } else {
        c += pow(10, a - list[i].first) * list[i].second;
      }
    }
  }
  d = 0;
  e = c;
  if (c != -1 && c != 0) {
    while (e != 0) {
      e /= 10;
      d += 1;
    }
  }
  if (c < d) {
    c = -1;
  }
  if (c == 0 && a > 1) {
    c = -1;
  }
  std::cout << c;
}
