#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> num(4);
  for (int i = 0; i < (m); i++) {
    int s, c;
    cin >> s >> c;
    if (num[s] == 0 || num[s] == c)
      num[s] = c;
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (num[1] == 0 && n != 1) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) cout << num[i];
}
