#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int ans[4] = {-1, -1, -1, -1};
  bool f = true;
  while (m--) {
    int s, c;
    cin >> s >> c;
    if (n != 1 && s == 1 && c == 0) f = false;
    if (ans[s] == -1)
      ans[s] = c;
    else {
      if (ans[s] != c) {
        f = false;
      }
    }
  }
  if (!f)
    cout << -1 << endl;
  else {
    int t[100];
    for (int i = 1; i <= n; i++) {
      if (ans[i] == -1 && i == 1)
        cout << 1;
      else if (ans[i] == -1 && i != 1)
        cout << 0;
      else if (ans[i] != -1)
        cout << ans[i];
    }
    cout << endl;
  }
}
