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