#include <bits/stdc++.h>
using namespace std;
const int INF = 2000000000;
const double pi = 3.1415926;
const int base = 1000000007;
int a[3];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.precision(20);
  int n, m;
  cin >> n;
  for (int i = 0; i < n; i++) {
    a[i] = -1;
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    int pos, z;
    cin >> pos >> z;
    pos--;
    if (a[pos] != -1 && a[pos] != z) {
      cout << -1;
      return 0;
    }
    a[pos] = z;
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == 0 && i == 0 && n != 1) {
      cout << -1;
      return 0;
    }
    if (a[i] == -1)
      cout << -a[i];
    else
      cout << a[i];
  }
  return 0;
}
