#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const long long dx4[4] = {1, 0, -1, 0};
const long long dy4[4] = {0, 1, 0, -1};
const long long dx8[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const double pi = acos(-1);
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;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
void solve() {
  std::ifstream in("sample.txt");
  std::cin.rdbuf(in.rdbuf());
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  long long s[m], c[m];
  for (size_t i = (0); i < (m); ++i) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  long long start = pow(10, n - 1);
  long long end = pow(10, n);
  long long ans = INF;
  for (long long i = start; i < end; i++) {
    bool isOK = true;
    string str = to_string(i);
    for (long long jm = 0; jm < m; jm++) {
      long long nows = s[jm];
      long long nowc = c[jm];
      long long nd = str[nows] - '0';
      if (nd != nowc) isOK = false;
    }
    if (isOK) ans = min(ans, i);
  }
  cout << ((ans == INF) ? -1 : ans) << endl;
}
signed main() {
  solve();
  return 0;
}
