#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int m;
  int x, y;
  cin >> n >> m;
  vector<int> dig(n, -1);
  while (m--) {
    cin >> x >> y;
    x--;
    if (dig[x] == -1)
      dig[x] = y;
    else if (dig[x] != y)
      dig[x] = -2;
  }
  if (dig[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (dig[0] == -1) dig[0] = 1;
  for (int i = 0; i < n; i++)
    if (dig[i] == -2) {
      cout << -1 << endl;
      return 0;
    }
  for (int i = 0; i < n; i++) {
    if (dig[i] == -1)
      cout << 0;
    else
      cout << dig[i];
  }
  cout << endl;
}
