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