#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
void d_err() { cerr << endl; }
template <typename H, typename... T>
void d_err(H h, T... t) {
  cerr << h << " ";
  d_err(t...);
}
long long INF = 1e16;
int inf = 1e9;
long long MOD = 1e9 + 7;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  int s[M], c[M];
  for (int i = (0); i < (M); ++i) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  for (int n = (0); n < (1000); ++n) {
    string S = to_string(n);
    if (S.size() < N) continue;
    bool f = true;
    for (int j = (0); j < (M); ++j) {
      if (S[s[j]] != c[j]) {
        f = false;
        break;
      }
    }
    if (f) {
      cout << n << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
