#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<char>> a(3);
  for (int i = 0; i < (m); i++) {
    int s;
    char c;
    cin >> s >> c;
    s--;
    a[s].emplace_back(c);
  }
  string res = "";
  for (int i = 0; i < n; i++) {
    bool ok = true;
    int k = int(a[i].size());
    char p;
    if (k > 0) p = a[i][0];
    for (int j = 0; j < k; j++) {
      if (a[i][j] != p) ok = false;
    }
    if (!ok) {
      cout << -1 << endl;
      return 0;
    }
    if (k == 0)
      res += (i == 0 ? '1' : '0');
    else {
      res += a[i][0];
    }
  }
  if (n > 1 && res[0] == '0')
    cout << -1 << endl;
  else
    cout << res << endl;
  return 0;
}
