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