#include <bits/stdc++.h>
using namespace std;
int main() {
  int s, n, m, flag[6], c, i, faulty = 0;
  memset(flag, -1, 6 * sizeof(int));
  cin >> n >> m;
  if (m == 0) cout << "0";
  for (i = 0; i < m; i++) {
    cin >> s >> c;
    if (s == 1 and c == 0 and n != 1) {
      faulty = 1;
      break;
    }
    if (flag[s] == -1 or flag[s] == c)
      flag[s] = c;
    else {
      faulty = 1;
      break;
    }
  }
  if (faulty == 1)
    cout << "-1";
  else if (m != 0) {
    if (flag[1] != -1)
      cout << flag[1];
    else
      cout << 1;
    if (flag[2] != -1)
      cout << flag[2];
    else if (n >= 2)
      cout << 0;
    if (flag[3] != -1)
      cout << flag[3];
    else if (n >= 2)
      cout << 0;
  }
  cout << endl;
  return 0;
}
