#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int t = m;
  int num[4] = {0};
  int flag = 1;
  while (m--) {
    int a, b;
    cin >> a >> b;
    if (num[a] && num[a] != b) flag = 0;
    num[a] = b;
  }
  if (num[1] == 0 && n != 1) flag = 0;
  if (t == 0) {
    if (n == 1)
      cout << 0;
    else {
      cout << 1;
      for (int i = 1; i < n; i++) cout << 0;
    }
  } else {
    if (flag)
      for (int i = 1; i <= n; i++) cout << num[i];
    else
      cout << -1;
  }
}
