#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long IINF = 1e18;
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int digit(int n) {
  if (n == 0) return 1;
  int res = 0;
  while (n) n /= 10, ++res;
  return res;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<char> c(M);
  for (long long i = 0; i < (M); ++i) cin >> s[i] >> c[i];
  for (long long i = 0; i < (1000); ++i) {
    if (digit(i) != N) continue;
    string S = to_string(i);
    for (long long j = 0; j < (M); ++j) {
      if (S[s[j] - 1] != c[j]) break;
      if (j == M - 1) {
        cout << i << '\n';
        return 0;
      }
    }
    if (i == 999) cout << -1 << '\n';
  }
}
