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