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