#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<string> nums = {"000", "010", "100"};
  vector<int> check(4, -1);
  int n, m;
  cin >> n >> m;
  string num = nums[n - 1];
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (check[s] >= 0 && check[s] != c) {
      cout << "-1\n";
      return 0;
    }
    check[s] = c;
    if (n == 3) {
      if (s == 1 && c == 0) {
        cout << "-1\n";
        return 0;
      }
    } else if (n == 2) {
      if ((s == 2 && c == 0) || (s == 1 && c != 0)) {
        cout << "-1\n";
        return 0;
      }
    } else if (n == 1) {
      if ((s == 2 && c != 0) || (s == 1 && c != 0)) {
        cout << "-1\n";
        return 0;
      }
    }
    num[s - 1] = '0' + c;
  }
  int ans = stoi(num);
  cout << ans << endl;
  return 0;
}
