#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  int ar[4];
  memset(ar, 0, sizeof(ar));
  bool flag = true;
  while (m--) {
    int i, v;
    cin >> i >> v;
    if (ar[i] == v || ar[i] == 0)
      ar[i] = v;
    else
      flag = false;
  }
  if (flag == false)
    cout << "-1" << endl;
  else if (ar[1] == 0)
    cout << "-1" << endl;
  else {
    for (int i = 1; i < n + 1; i++) cout << ar[i];
    cout << endl;
  }
  return 0;
}
