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