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