#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  long long ch[3];
  for (long long i = 0; i < 3; i++) {
    ch[i] = -1;
  }
  for (long long i = 0; i < m; i++) {
    long long x, z;
    cin >> x >> z;
    x--;
    if (ch[x] == -1) {
      ch[x] = z;
    } else {
      if (ch[x] != z) {
        cout << -1;
        return 0;
      }
    }
  }
  if (ch[0] == 0) {
    cout << -1;
    return 0;
  }
  for (long long i = 0; i < n; i++) {
    if (ch[i] == -1) {
      cout << 0;
    } else {
      cout << ch[i];
    }
  }
  return 0;
}
