#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  vector<int> d(3, -1);
  for (int i = 0; i < (int)m; ++i) {
    int s, c;
    cin >> s >> c;
    if (d[s - 1] != -1 && c != d[s - 1]) {
      cout << -1 << endl;
      return 0;
    }
    d[s - 1] = c;
  }
  for (int i = 0; i < (int)1000; ++i) {
    string s = to_string(i);
    if (s.size() != n) continue;
    bool ok = true;
    for (int j = 0; j < (int)m; ++j) {
      if (d[j] == -1) continue;
      if (s[j] != ('0' + d[j])) ok = false;
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
