#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  int n, m, max;
  long long ans = 1000000000000;
  int s[10], c[10];
  bool flag = false;
  std::string number;
  std::cin >> n >> m;
  for (long long i = 0; i < (long long)(m); i++) std::cin >> s[i] >> c[i];
  max = pow(10, n);
  for (long long i = ((n == 1) ? pow(10, n - 1) : 0); i <= (max - 1); i++) {
    number = std::to_string(i);
    flag = true;
    for (long long j = 0; j < (long long)(m); j++) {
      if (int(number[s[j] - 1] - '0') != c[j]) {
        flag = false;
      }
    }
    if (flag) ans = std::min(ans, i);
  }
  if (ans == 1000000000000)
    std::cout << "-1" << '\n';
  else
    std::cout << ans << '\n';
  return 0;
}
