#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln = '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < (m); i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  int mn, mx;
  if (n == 1) mn = 0, mx = 9;
  if (n == 2) mn = 10, mx = 99;
  if (n == 3) mn = 100, mx = 999;
  int res = -1;
  for (int i = mn; i <= mx; i++) {
    bool fg = true;
    string num = to_string(i);
    for (int j = 0; j < (m); j++) {
      if (c[j] != num[s[j]]) {
        fg = false;
        break;
      }
    }
    if (fg) {
      res = i;
      break;
    }
  }
  cout << res << ln;
}
