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