#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  int s[m], t[m];
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> t[i];
  }
  vector<int> check(n, 0);
  vector<int> seen(n, 0);
  for (int i = 0; i < m; i++) {
    if (seen[s[i] - 1] == 1 && t[i] != check[s[i] - 1]) {
      cout << -1 << endl;
      return 0;
    }
    if (seen[s[i] - 1] == 0) {
      check[s[i] - 1] = t[i];
      seen[s[i] - 1] = 1;
    }
  }
  if (seen[0] == 1 && check[0] == 0 && n != 1) {
    cout << -1 << endl;
    return 0;
  } else {
    for (int i = 0; i < n; i++) {
      if (seen[i] == 0 && i != 0)
        cout << 0;
      else if (seen[i] == 0 && i == 0)
        cout << 1;
      else
        cout << check[i];
    }
    cout << endl;
  }
  return 0;
}
