#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int n, m, tmp, tmp2, ok = 1;
  vector<int> vc;
  cin >> n >> m;
  vc = vector<int>(n + 1, -1);
  for (int i = 0; i < m; ++i) {
    cin >> tmp >> tmp2;
    if (vc[tmp] == -1)
      vc[tmp] = tmp2;
    else {
      if (vc[tmp] != tmp2) {
        ok = 0;
        break;
      }
    }
  }
  if (!ok || vc[1] == 0)
    cout << -1 << '\n';
  else {
    for (int i = 1; i <= n; ++i) {
      if (vc[i] == -1) {
        if (i == 1)
          cout << 1;
        else
          cout << 0;
      } else
        cout << vc[i];
    }
    cout << '\n';
  }
  return 0;
}
