#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> sc(M);
  for (int i = 0; i < M; i++) cin >> sc[i].first >> sc[i].second;
  int init = 0;
  int endon = 10;
  if (N == 2) {
    init = 10;
    endon = 100;
  }
  if (N == 3) {
    init = 100;
    endon = 1000;
  }
  long long ans = 10000;
  for (int i = init; i < endon; i++) {
    for (int j = 0; j < M; j++) {
      long long waru = 1;
      if (sc[j].first == 1) waru = 1;
      if (sc[j].first == 2) waru = 10;
      if (sc[j].first == 3) waru = 100;
      if (i / (init / waru) % 10 != sc[j].second) {
        break;
      }
      if (j == M - 1) {
        if (i < ans) ans = i;
      }
    }
  }
  if (ans != 10000)
    cout << ans << endl;
  else if (M == 0)
    cout << init << endl;
  else
    cout << -1 << endl;
  return 0;
}
