#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using ll = long long;
using M = map<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v(n);
  for (int i = 0; i < (int)(n); i++) v[i] = 0;
  int a, b;
  int ans = 0;
  for (int i = 0; i < (int)(m); i++) {
    cin >> a >> b;
    if (v[a - 1] == 0)
      v[a - 1] = b;
    else if (v[a - 1] != b)
      ans = -1;
    else {
    }
  }
  if (ans > -1) {
    for (int i = 0; i < (int)(n); i++) {
      if (i == 0 && v[i] == 0) {
        ans = -1;
        break;
      }
      ans *= 10;
      ans += v[i];
    }
  }
  cout << ans << endl;
  return 0;
}
