#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int mo = 1e9 + 7;
constexpr int inf = 1 << 30;
constexpr ll infl = 1ll << 60;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int p10 = 1;
  for (int i = 0; i < n - 1; ++i) p10 *= 10;
  vector<pair<int, int>> v(m);
  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    v[i] = {s, c};
  }
  for (int i = p10; i < p10 * 10; ++i) {
    string s = to_string(i);
    bool ng = false;
    for (auto cur : v) {
      if (s.substr(cur.first, 1) != to_string(cur.second)) ng = true;
    }
    if (!ng) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
