#include <bits/stdc++.h>
using namespace std;
inline void ci(void) { return; }
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest) {
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void) {
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest) {
  cout << first << " ";
  co(rest...);
  return;
}
int main() {
  int N, M;
  ci(N, M);
  vector<int> s(M), c(M);
  for (int i = (int)(0); i < (int)(M); i++) {
    ci(s.at(i), c.at(i));
  }
  for (int i = (int)(0); i < (int)(1000); i++) {
    int A = 0;
    for (int j = (int)(0); j < (int)(M); j++) {
      if (s.at(j) == 3 && i % 10 == c.at(j)) {
        A++;
      }
      if (s.at(j) == 2 && (i % 100) / 10 == c.at(j)) {
        A++;
      }
      if (s.at(j) == 1 && i / 100 == c.at(j)) {
        A++;
      }
    }
    if (A == M && to_string(i).length() == N) {
      co(i);
      return 0;
    }
  }
  co(-1);
}
