#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> num(n, -1);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    if (num[x - 1] == -1) {
      num[x - 1] = y;
    } else if (num[x - 1] != y) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (num[0] == 0) {
    cout << -1 << endl;
  }
  int ans = 0, k = 1;
  for (int i = n - 1; i >= 0; i--) {
    if (num[i] != -1) {
      ans += num[i] * k;
    }
    k *= 10;
  }
  cout << ans << endl;
}
