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