#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
bool compare_by_b(pair<long long, long long> a, pair<long long, long long> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}
void solve(long long N, long long M, std::vector<long long> s,
           std::vector<long long> c) {
  map<int, int> m;
  for (int i = (0); i < (M); ++i) {
    if (m[s[i]]) {
      m[s[i]] = c[i];
    }
    if (s[i] == 1 && c[i] == 0) {
      cout << -1 << endl;
      return;
    }
  }
  int lim;
  if (N == 1)
    lim = 9;
  else if (N == 2)
    lim = 99;
  else
    lim = 999;
  for (int i = 0; i <= lim; i++) {
    string str = to_string(i);
    bool flag = true;
    for (int j = (0); j < (s.size()); ++j) {
      if (c[j] == (int)(str[s[j] - 1] - '0')) {
      } else {
        flag = false;
      }
    }
    if (flag) {
      cout << i << endl;
      return;
    }
  }
  cout << -1 << endl;
  return;
}
int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> s(M);
  std::vector<long long> c(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &s[i]);
    scanf("%lld", &c[i]);
  }
  solve(N, M, std::move(s), std::move(c));
  return 0;
}
