#include <bits/stdc++.h>
using namespace std;
long long int MOD = 1e9 + 7;
int main(void) {
  int N, M;
  cin >> N >> M;
  vector<int> ans(N + 3, -1);
  int www = 0;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < M; ++i) {
    int S, C;
    cin >> S >> C;
    s[i] = S;
    c[i] = C;
    if (ans[S - 1] == -1 || ans[S - 1] == C) {
      ans[S - 1] = C;
    } else {
      www = 1;
    }
  }
  if (www == 1) {
    cout << "-1" << endl;
    return 0;
  }
  for (int i = (N == 1) ? 0 : pow(10, N - 1); i <= pow(10, N) - 1; ++i) {
    string S = to_string(i);
    bool ok = false;
    for (int j = 0; j < M; ++j) {
      if (S[s[j] - 1] - '0' == c[j]) {
        ok = true;
      } else {
        ok = false;
        break;
      }
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
