#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long double EPS = 0.0000000001;
int n, m;
int main() {
  cin >> n >> m;
  vector<int> s(m), c(m);
  vector<int> v(n + 1);
  for (long long i = 0; i < n + 1; i++) v[i] = -1;
  for (long long i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    if (v[s[i]] != -1 and v[s[i]] != c[i]) {
      cout << -1 << endl;
      return 0;
    }
    v[s[i]] = c[i];
  }
  if (v[1] == 0 and n > 1) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  for (long long i = 1; i < n + 1; i++) {
    if (v[i] != -1)
      ans = (ans + v[i]) * 10;
    else
      ans = ans * 10;
  }
  cout << ans / 10 << endl;
  return 0;
}
