#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
using seika = string;
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;
inline void print() { cout << endl; }
template <typename First, typename... Rest>
void print(const First &first, const Rest &...rest) {
  cout << first << ' ';
  print(rest...);
}
void solve() {
  int n, m;
  cin >> n >> m;
  akari<int> cond(n, -1);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (cond[s] != -1 && cond[s] != c) {
      cout << -1 << endl;
      return;
    }
    cond[s] = c;
  }
  if (n == 1 && cond[0] == 0) {
    cout << 0 << endl;
    return;
  }
  int beg = 1;
  for (int i = 1; i < n; i++) {
    beg *= 10;
  }
  for (int x = beg; x < beg * 10; x++) {
    bool ok = 1;
    int t = beg;
    for (int i = 0; i < n; i++) {
      if (cond[i] != -1 && x / t % 10 != cond[i]) {
        ok = 0;
      }
      t /= 10;
    }
    if (ok) {
      cout << x << endl;
      return;
    }
  }
  cout << -1 << endl;
}
int main() {
  solve();
  return 0;
}
