#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
vector<pair<int, int>> conds;
vector<int> calc_digits(int x) {
  if (x == 0) {
    return {' ', ' ', 0};
  }
  vector<int> res;
  while (x != 0) {
    int d = x % 10;
    res.push_back(d);
    x /= 10;
  }
  while ((int)res.size() < 3) {
    res.push_back(' ');
  }
  reverse(res.begin(), res.end());
  return res;
}
int pow(const int base, int n) {
  int ans = 1;
  if (n <= 0) {
    return ans;
  }
  return base * pow(base, n - 1);
}
int solve(const int N, const int M) {
  for (int i = pow(10, N - 1); i < pow(10, N); i++) {
    vector<int> digits = calc_digits(i);
    bool ok = true;
    for (auto &cond : conds) {
      if (digits[cond.first] != cond.second) {
        ok = false;
        break;
      }
    }
    if (ok) {
      return i;
    }
  }
  return -1;
}
int main(void) {
  int N, M;
  cin >> N >> M;
  conds.resize(M);
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    conds[i] = {s, c};
  }
  int ans = solve(N, M);
  cout << ans << endl;
  return 0;
}
