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