#include <bits/stdc++.h>
using namespace std;
template <class A>
void p(A a) {
  cout << (a) << endl;
}
template <class A, class B>
void p(A a, B b) {
  cout << a << " ";
  p(b);
}
template <class A, class B, class C>
void p(A a, B b, C c) {
  cout << a << " ";
  p(b, c);
}
template <class A, class B, class C, class D>
void p(A a, B b, C c, D d) {
  cout << a << " ";
  p(b, c, d);
}
int INF = numeric_limits<int>::max();
int main(void) {
  int N, M;
  cin >> N >> M;
  int max_n;
  if (N == 1) {
    max_n = 10;
  } else if (N == 2) {
    max_n = 100;
  } else if (N == 3) {
    max_n = 1000;
  }
  int s[N];
  char c[N];
  for (int i = 0; i < int(M); ++i) {
    cin >> s[i] >> c[i];
  }
  string S;
  for (int i = 0; i < int(max_n); ++i) {
    S = to_string(i);
    bool marker = true;
    for (int j = 0; j < int(M); ++j) {
      if (S[s[j] - 1] != c[j]) {
        marker = false;
      }
    }
    if (marker) {
      p(S);
      return 0;
    }
  }
  p("-1");
  return 0;
}
