#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  int moves[m][2];
  int ans[n];
  for (int i = 0; i < m; i++) cin >> moves[i][0] >> moves[i][1];
  bool done[n], legit = true;
  memset(done, 0, sizeof(bool));
  memset(ans, 0, sizeof(ans));
  for (int i = 0; i < m; i++) {
    int it = moves[i][0] - 1;
    int num = moves[i][1];
    if (!done[it]) {
      ans[it] = num;
      done[it] = true;
    } else if (done[it] && num != ans[it])
      legit = false;
  }
  unsigned long long int res = 0;
  if (legit) {
    unsigned long long int mult = 1;
    for (int i = 0; i < n - 1; i++) mult *= 10;
    for (int i = 0; i < n; i++) {
      res += (mult * ans[i]);
      mult = mult / 10;
    }
    if (res > 0)
      cout << res;
    else
      cout << -1;
  } else
    cout << -1;
  cout << "\n";
  return 0;
}
