#include <bits/stdc++.h>
using namespace std;
int main() {
  int ans[3] = {-1, -1, -1}, n, m, i, s, c;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> s >> c;
    if (ans[s - 1] != -1 && ans[s - 1] != c) {
      cout << "-1";
      return 0;
    }
    ans[s - 1] = c;
  }
  if (ans[0] == 0 && n != 1) {
    cout << "-1";
    return 0;
  }
  for (i = 0; i < n; i++) {
    if (ans[i] == -1)
      cout << '0';
    else
      cout << ans[i];
  }
  return 0;
}
