#include <bits/stdc++.h>
using namespace std;
int o[4];
int main() {
  std::ios::sync_with_stdio(false);
  int n, m, k, x;
  while (cin >> n >> m) {
    int flag = 1;
    o[1] = -1;
    o[2] = -1;
    o[3] = -1;
    while (m--) {
      cin >> k >> x;
      if (o[k] == -1 || o[k] == x)
        o[k] = x;
      else
        flag = 0;
    }
    if (flag && o[1] != 0) {
      if (n != 1 && o[1] == -1) o[1] = 1;
      for (int i = 1; i <= n; i++)
        if (o[i] == -1) o[i] = 0;
      for (int i = 1; i <= n; i++) cout << o[i];
      cout << endl;
    } else
      cout << -1 << endl;
  }
  return 0;
}
