#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll x, ll y) {
  ll a;
  while (y != 0) {
    a = x % y;
    x = y;
    y = a;
  }
  return x;
}
int main() {
  int n, m, cnt = 0, ans = 0;
  cin >> n >> m;
  map<int, int> mp;
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    vec.at(i) = 0;
  }
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (vec.at(s - 1) != 0 && mp.at(s) != c)
      cnt++;
    else {
      mp[s] = c;
      vec.at(s - 1) += 1;
      ans += (pow(10, n - s)) * c;
    }
  }
  if (cnt == 0 && (n != 1 && ans != 0))
    cout << ans << endl;
  else
    cout << -1 << endl;
}
