#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<P> vec(m);
  for (ll i = 0; i < m; i++) cin >> vec[i].first >> vec[i].second;
  for (ll x = 0; x < 1000; x++) {
    int keta = 0;
    vector<int> digit;
    while (x) {
      keta++;
      digit.push_back(x % 10);
      x /= 10;
    }
    if (keta != n) continue;
    reverse(digit.begin(), digit.end());
    bool ok = true;
    for (ll i = 0; i < m; i++) {
      if (digit[vec[i].first - 1] != vec[i].second) ok = false;
    }
    if (ok) {
      for (auto c : digit) cout << c;
      cout << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
