#include <bits/stdc++.h>
using namespace std;
int a[505];
int n, m;
int b[2][505];
int ans = 0, q, tmp;
int sum[505];
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) cin >> b[0][i] >> b[1][i];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      tmp = 0;
      for (int k = 1; k <= m; k++) {
        if ((b[0][k] <= i && i <= b[1][k]) &&
            (!((b[0][k] <= j && j <= b[1][k])))) {
          ++tmp;
        }
      }
      if (ans < a[j] - a[i] + tmp) {
        ans = a[j] - a[i] + tmp;
        q = 0;
        for (int k = 1; k <= m; k++) {
          if ((b[0][k] <= i && i <= b[1][k]) &&
              (!((b[0][k] <= j && j <= b[1][k])))) {
            sum[++q] = k;
          }
        }
      }
    }
  cout << ans << endl;
  cout << q << endl;
  for (int i = 1; i <= q; i++) {
    cout << sum[i];
    if (i == q)
      cout << endl;
    else
      cout << ' ';
  }
  return 0;
}
