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