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