#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  string ans = "    ";
  cin >> a >> b;
  for (int i = 0; i < b; i++) {
    int c;
    char d;
    cin >> c >> d;
    c--;
    if (ans[c] == ' ') ans[c] = d;
  }
  if (ans == "    " && a == 1) {
    cout << "0" << endl;
    return 0;
  }
  if (ans[0] == '0') {
    cout << "-1" << endl;
    return 0;
  }
  if (ans[0] == ' ' && ans[0] != '0')
    ans[0] = '1';
  else if (ans[0] == '0') {
    cout << "-1";
    return 0;
  }
  if (ans[1] == ' ' && a - 1 >= 0) ans[1] = '0';
  if (ans[2] == ' ' && a - 2 >= 0) ans[2] = '0';
  cout << ans;
  return 0;
}
