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