#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int func(int n) {
  int ret = 1;
  while (n > 0) {
    ret *= 10;
    n--;
  }
  return ret;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> val(n, 0);
  val[0] = 1;
  vector<bool> vis(n, false);
  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    if (s == 0 & c == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (vis[s] && c != val[s]) {
      cout << -1 << endl;
      return 0;
    }
    val[s] = c;
    vis[s] = true;
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += val[i] * func(n - i - 1);
  }
  cout << ans << endl;
  return 0;
}
