#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  int tar[3] = {-1, -1, -1};
  int x, y;
  if (b == 0) {
    int hi = 0;
    if (a == 2) hi = 10;
    if (a == 3) hi = 100;
    cout << hi << endl;
    return 0;
  }
  for (int i = 0; i < b; i++) {
    cin >> x >> y;
    if (tar[x - 1 + (3 - a)] == -1 || tar[x - 1 + (3 - a)] == y)
      tar[x - 1 + (3 - a)] = y;
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < a; i++) {
    if (tar[i] != -1 && tar[i] != 0) {
      if (3 - i > a) {
        cout << -1 << endl;
        return 0;
      }
      int diff = -1;
      if (3 - i < a) {
        diff = a - (3 - i);
        cout << 1, diff--;
        while (diff != 0) {
          cout << 0, diff--;
        }
      }
      for (int j = i; j < 3; j++) {
        if (tar[j] == -1)
          cout << 0;
        else
          cout << tar[j];
      }
      cout << endl;
      return 0;
    }
    if (tar[i] == 0 && 3 - i == a && a > 1) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (tar[2] == 0) {
    if (a == 1)
      cout << 0 << endl;
    else if (a == 2 && tar[1] == -1)
      cout << 10 << endl;
    else if (a == 3 && tar[0] == -1 && tar[1] == -1)
      cout << 100 << endl;
    else
      cout << -1 << endl;
    return 0;
  } else
    cout << -1 << endl;
}
