#include <bits/stdc++.h>
using namespace std;
int syc(long i, long Min, long Max) {
  if (Min <= i && i <= Max) {
    return 1;
  } else {
    exit(1);
  }
}
int main() {
  int n, m, x, y;
  cin >> n >> m;
  int s[m], c[m], ans[m];
  for (int i = 0; i < m; i++) {
    cin >> s[i];
    cin >> c[i];
    ans[i] = 0;
  }
  for (int i = 0; i < m; i++) {
    if (ans[s[i] - 1] == 0) {
      ans[s[i] - 1] = c[i];
    } else if (ans[s[i] - 1] != 0 && ans[s[i] - 1] != c[i]) {
      cout << "-1" << endl;
      return 0;
    }
  }
  int ans_is = 0;
  for (int i = 0; i < m; i++) {
    ans_is += ans[i] * pow(10, m - 1 - i);
  }
  if (ans_is > 0) {
    cout << ans_is << endl;
  } else {
    cout << "-1" << endl;
  }
  return 0;
}
