#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int s, c;
  int flag = 0;
  int ans = 0;
  int a[10010] = {0};
  cin >> n >> m;
  if (n == 1 && m == 0) {
    cout << "0" << endl;
    return 0;
  }
  int t = m;
  while (t--) {
    cin >> s >> c;
    if (s == 1 && c == 0) {
      cout << "-1" << endl;
      return 0;
    }
    if (a[s] == 0)
      a[s] = c;
    else {
      if (c != a[s]) {
        cout << "-1" << endl;
        return 0;
      }
    }
  }
  if (n > 1 && !a[1]) {
    cout << "-1" << endl;
    return 0;
  }
  for (int i = 1; i <= m; i++) ans = ans + pow(10, (m - i)) * a[i];
  cout << ans << endl;
  return 0;
}
