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