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