#include <bits/stdc++.h>
using namespace std;
int MOD = 1000000007;
int main() {
  int n;
  int m;
  cin >> n >> m;
  int ret = 0;
  vector<vector<int>> c(m, vector<int>(2));
  for (int i = 0; i < m; i++) {
    cin >> c[i][0] >> c[i][1];
    c[i][0]--;
  }
  vector<int> hasc(n, -1);
  int confli = 0;
  for (int i = 0; i < m; i++) {
    int pos = c[i][0];
    int v = c[i][1];
    if (hasc[pos] == -1) {
      hasc[pos] = v;
    } else if (hasc[pos] != v) {
      confli = 1;
      break;
    }
  }
  if (confli == 1) {
    cout << -1 << endl;
    return 0;
  }
  if (hasc[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  ret = 0;
  for (int i = 0; i < n; i++) {
    if (hasc[i] == -1) {
      hasc[i] = 1;
    }
    ret *= 10;
    ret += hasc[i];
  }
  cout << ret << endl;
  return 0;
}
