#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] == -1 || tar[x - 1] == y)
      tar[x - 1] = 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;
      }
      for (int j = i; j < 3; j++) {
        if (tar[j] == -1)
          cout << 0;
        else
          cout << tar[j];
      }
      cout << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
