#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i, j, n, m, ans = 0;
  cin >> n >> m;
  long long lst[3] = {1, 0, 0}, count[3] = {0};
  for (i = 0; i < m; i++) {
    int keta, num;
    cin >> keta >> num;
    if (count[keta - 1] != 0) {
      if (lst[keta - 1] != num) {
        cout << -1 << endl;
        return 0;
      }
    }
    lst[keta - 1] = num;
    count[keta - 1]++;
  }
  if (n == 1)
    cout << lst[0] << endl;
  else {
    if (lst[0] == 0)
      cout << -1 << endl;
    else {
      for (i = 0; i < n; i++) {
        ans += lst[i] * pow(10, n - i - 1);
      }
      cout << ans << endl;
    }
  }
}
