#include <bits/stdc++.h>
using namespace std;
const int N = 2000 + 5;
int a[5] = {-1, -1, -1, -1, -1};
int main() {
  int n, m;
  cin >> n >> m;
  int flag = 0;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    if (x == 1 && y == 0 && n != 1) flag = 1;
    if (a[x] == -1) {
      a[x] = y;
    }
    if (a[x] != -1) {
      if (y != a[x]) flag = 1;
    }
    if (x == 1 && y == 0 && n == 1 && flag == 0) flag = 2;
  }
  if (flag == 1)
    cout << -1 << endl;
  else if (flag == 2)
    cout << 0 << endl;
  else {
    int z = 0;
    if (a[1] == -1)
      cout << 1;
    else
      cout << a[1];
    for (int i = 2; i <= n; i++) {
      if (a[i] == -1)
        cout << 0;
      else
        cout << a[i];
    }
    cout << endl;
  }
  return 0;
}
