// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <boost/lexical_cast.hpp>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

const array<string, 3> MIN = {"000", "010", "100"};

int main() {
  int N, M;
  cin >> N >> M;
  string t = MIN[N - 1];
  bitset<4> bs;
  bool ok = true;
  REP(i, M) {
    int s, c;
    cin >> s >> c;
    if (!bs[s] || boost::lexical_cast<int>(t[s - 1]) == c) {
      t[s - 1] = boost::lexical_cast<char>(c);
      bs.set(s);
    } else {
      ok = false;
    }
  }
  if (!ok) {
    cout << -1 << endl;
    return 0;
  }
  int res = boost::lexical_cast<int>(t);
  if (boost::lexical_cast<string>(res).length() == N) {
    cout << res << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
