#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;
  int ans = 0;
  vector<int> a(n, 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];
  }
  for (int i = 0; i < (int)(n); i++)
    if (a[i] == INF) a[i] = 0;
  int b = 0;
  if (n >= 2) b = 1;
  for (int i = 0; i < (int)(n - 1); i++) b *= 10;
  int d = b;
  for (int i = 0; i < (int)(n); i++) {
    if (i != n - 1) {
      if (1 <= a[i] && a[i] < 10) {
        ans += a[i] * d;
        d /= 10;
      }
    } else {
      ans += a[i];
    }
  }
  if (ans < b) ans = -1;
  cout << ans << endl;
  return 0;
}
