#include <bits/stdc++.h>
using namespace std;
int nnn(int N, int s) {
  int a = 1;
  for (int i = 0; i < N - s; i++) {
    a *= 10;
  }
  return a;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  int flag = 0;
  int ans = 0;
  for (int i = 0; i < M; i++) {
    int a = s[i];
    int b = c[i];
    for (int j = 0; j < M; j++) {
      if (j == i) continue;
      if (a == s[j] && b != c[j]) {
        flag = 1;
        break;
      }
      if (a == s[j] && b == c[j]) {
        s[i] = 0;
        c[i] = 0;
      }
    }
    if (a == 1 && b == 0 && N > 1) {
      flag = 1;
      break;
    }
  }
  for (int i = 0; i < M; i++) {
    int b = nnn(N, s[i]);
    ans += b * c[i];
  }
  if (flag == 0) cout << ans << endl;
  if (flag == 1) cout << "-1" << endl;
  return 0;
}
