#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<int> s(m), c(m);
  for (int i = 0; i < (int)(m); i++) cin >> s[i] >> c[i];
  const int INF = 10;
  vector<int> a(3, INF);
  for (int i = 0; i < (int)(m); i++) {
    if (a[s[i] - 1] != INF && a[s[i] - 1] != c[i]) {
      cout << -1 << endl;
      return 0;
    }
    a[s[i] - 1] = c[i];
  }
  int b = 0;
  if (n >= 2) {
    b = 1;
    for (int i = 0; i < (int)(n - 1); i++) b *= 10;
  }
  for (int i = 0; i < (int)(3); i++)
    if (a[i] == INF) a[i] = 0;
  int ans = a[0] * 100 + a[1] * 10 + a[2];
  if (b > ans) ans = -1;
  cout << ans << endl;
  return 0;
}
