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