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