#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int a[5], b[5], res[3] = {0};
  cin >> n >> m;
  int flag = 0, flag2 = 0;
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    if (n != 1 && a[i] == 1 && b[i] == 0) flag = 1;
    if (n == 1 && b[i] == 0) flag2 = 1;
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i] == a[j]) {
        if (b[i] == b[j])
          continue;
        else
          flag = 1;
      }
    }
  }
  if (flag)
    cout << "-1";
  else if (flag2)
    cout << '0';
  else {
    for (int i = 0; i < m; i++) {
      res[a[i] - 1] = b[i];
    }
    if (res[0] == 0) res[0] = 1;
    for (int i = 0; i < n; i++) cout << res[i];
  }
  return 0;
}
