#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
const long long int INF = 99999999999999999;
long long int N, M, Q, A[255][255], b[20], sum = 0, res = 0, sta = 1, s[10],
                                           c[10];
int main() {
  cout << fixed << setprecision(18);
  cin >> N >> M;
  for (int i = 1; i < N; i++) {
    sta *= 10;
  }
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  if (sta == 1) {
    sta = 0;
  }
  for (int i = sta; i < max(sta * 10, 10LL); i++) {
    bool key = true;
    for (int j = 0; j < M; j++) {
      if (s[j] == 1) {
        if (i / sta != c[j]) {
          key = false;
        }
      } else if (s[j] == 2) {
        if ((i % sta) / 10 != c[j]) {
          key = false;
        }
      } else {
        if (i % 10 != c[j]) {
          key = false;
        }
      }
    }
    if (key) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
