#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void CHMAX(T& a, const T b) {
  if (a < b) a = b;
}
template <typename T>
inline void CHMIN(T& a, const T b) {
  if (a > b) a = b;
}
constexpr long long MOD = 1000000007ll;
const double EPS = 1e-11;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, s[10], C[10];
  cin >> n >> m;
  for (int i = 0; i < (m); ++i) {
    cin >> s[i] >> C[i];
    --s[i];
  }
  int ans = -1;
  for (int i = 0; i < (1000); ++i) {
    int x = i;
    int a = x / 100;
    int b = (x - a * 100) / 10;
    int c = x % 10;
    bool ok = true;
    int cnt = 0;
    while (x > 0) {
      x /= 10;
      ++cnt;
    }
    if (cnt != n) {
      continue;
    }
    for (int j = 0; j < (m); ++j) {
      if (s[j] == 0) {
        if (C[j] != a) {
          ok = false;
          break;
        }
      }
      if (s[j] == 1) {
        if (C[j] != b) {
          ok = false;
          break;
        }
      }
      if (s[j] == 2) {
        if (C[j] != c) {
          ok = false;
          break;
        }
      }
    }
    if (ok) {
      ans = i;
      break;
    }
  }
  cout << ans << '\n';
  return 0;
}
