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