#include <bits/stdc++.h>
using namespace std;
int ans[4];
int main() {
  int n, m;
  cin >> n >> m;
  ans[1] = ans[2] = ans[3] = -1;
  int fg = 0;
  while (m--) {
    int a, b;
    cin >> a >> b;
    if (ans[a] == -1 || b == ans[a]) {
      ans[a] = b;
    } else
      fg = 1;
  }
  if (ans[1] == -1) fg = 1;
  if (n != 1 && ans[1] == 0) fg = 1;
  if (fg == 1)
    cout << -1;
  else {
    for (int i = 1; i <= n; i++) {
      if (ans[i] == -1)
        cout << 0;
      else
        cout << ans[i];
    }
    cout << endl;
  }
  return 0;
}
