#include <bits/stdc++.h>
using namespace std;
int N, M, tS, tC;
vector<int> s, c;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> tS >> tC;
    s.push_back(tS);
    c.push_back(tC);
    if (N != 1 and tS == 1 and tC == 0) {
      cout << -1;
      return 0;
    }
  }
  bool found = false;
  int number;
  for (number = 0; number < 1000; number++) {
    string str = to_string(number);
    bool accepted = true;
    if (str.size() == N) {
      for (int j = 0; j < M; j++) {
        if (str[s[j] - 1] != c[j] + '0') accepted = false;
      }
    }
    if (accepted) {
      found = true;
      break;
    }
  }
  if (found)
    cout << number << "\n";
  else
    cout << "-1\n";
  return 0;
}
