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